public void Close() { lock (initializationLock) { try { if (null != requestQueue) { requestQueue.Stop(); } if (null != incomingStreamHandler) { incomingStreamHandler.Stop(); incomingStreamHandler = null; } if (null != outgoingStreamHandler) { outgoingStreamHandler.Stop(); outgoingStreamHandler = null; } if (null != socket) { socket.Close(); socket = null; } } catch (Exception e) { Debug.WriteLine("Error closing socket: " + e.Message); } } }
public bool Connect(string host, int port) { lock (initializationLock) { if (IsConnected()) { Close(); } try { socket = new TcpClient(host, port); //notify connection change if (null != connectionListener) { connectionListener.OnGazeApiConnectionStateChanged(socket.Connected); } incomingStreamHandler = new IncomingStreamHandler(socket, responseListener, connectionListener, this); incomingStreamHandler.Start(); outgoingStreamHandler = new OutgoingStreamHandler(socket, requestQueue, connectionListener, this); outgoingStreamHandler.Start(); } catch (SocketException se) { Debug.WriteLine("Unable to open socket. Is Tracker Server running? Exception: " + se.Message); //notify connection change if (null != connectionListener) { connectionListener.OnGazeApiConnectionStateChanged(false); } Close(); return(false); } catch (Exception e) { Debug.WriteLine("Exception while establishing socket connection. Is Tracker Server running? Exception: " + e.Message); Close(); return(false); } return(true); } }
public bool Connect(string host, int port) { Close(); try { outEvent = new WaitHandleWrap(); socket = new TcpClient(host, port); incomingStreamHandler = new IncomingStreamHandler(socket, responseListener); incomingStreamHandler.Start(); outgoingStreamHandler = new OutgoingStreamHandler(socket, requestQueue, outEvent); outgoingStreamHandler.Start(); } catch (Exception e) { Debug.WriteLine("Error opening socket. Is Tracker Server running? " + e.Message); Close(); return(false); } return(true); }
public bool Connect(string host, int port) { Close(); try { outEvent = new WaitHandleWrap(); socket = new TcpClient(host, port); incomingStreamHandler = new IncomingStreamHandler(socket, responseListener); incomingStreamHandler.Start(); outgoingStreamHandler = new OutgoingStreamHandler(socket, requestQueue, outEvent); outgoingStreamHandler.Start(); } catch (Exception e) { Debug.WriteLine("Error opening socket. Is Tracker Server running? " + e.Message); Close(); return false; } return true; }
public void Close() { lock (initializationLock) { try { if (null != requestQueue) requestQueue.Stop(); if (null != incomingStreamHandler) { incomingStreamHandler.Stop(); incomingStreamHandler = null; } if (null != outgoingStreamHandler) { outgoingStreamHandler.Stop(); outgoingStreamHandler = null; } if (null != socket) { socket.Close(); socket = null; } } catch (Exception e) { Debug.WriteLine("Error closing socket: " + e.Message); } } }
public bool Connect(string host, int port) { lock (initializationLock) { if (IsConnected()) Close(); try { socket = new TcpClient(host, port); //notify connection change if (null != connectionListener) connectionListener.OnGazeApiConnectionStateChanged(socket.Connected); incomingStreamHandler = new IncomingStreamHandler(socket, responseListener, connectionListener, this); incomingStreamHandler.Start(); outgoingStreamHandler = new OutgoingStreamHandler(socket, requestQueue, connectionListener, this); outgoingStreamHandler.Start(); } catch (SocketException se) { Debug.WriteLine("Unable to open socket. Is Tracker Server running? Exception: " + se.Message); //notify connection change if (null != connectionListener) connectionListener.OnGazeApiConnectionStateChanged(false); Close(); return false; } catch (Exception e) { Debug.WriteLine("Exception while establishing socket connection. Is Tracker Server running? Exception: " + e.Message); Close(); return false; } return true; } }