Download A. Fernandez, V. Fernandez, Robotic Arm Remote Control
Transcript
try
{
tcpListener = new TcpListener(ip, port);
tcpListener.Start();
while (true)
{
try
{
// accept the connection from a client
Console.WriteLine("\nWaiting for a connection... ");
success = false;
tcpClient = tcpListener.AcceptTcpClient();
Console.WriteLine("a client connected!");
networkStream = tcpClient.GetStream();
networkStream.Flush();
// if the robot server is running, terminate it so
the new robot server
// can be installed
if (p != null && !p.HasExited)
{
try
{
Console.WriteLine("Proccess " + p.Id +
" is running, terminating it");
p.Kill();
p.WaitForExit();
p = null;
GC.Collect();
Console.WriteLine("Done!");
}
catch (Exception ex)
{
Console.WriteLine("Failed to terminante robot
server");
}
}
try
{
using (Stream stream = new FileStream(filepath,
FileMode.Create, FileAccess.ReadWrite))
{
// Buffer for reading the stream
Byte[] bytes = new Byte[1024];
int length;
// get the new robot server sent by the
client
while ((length =
networkStream.Read(bytes, 0,
bytes.Length)) != 0)
{
62 | P a g e