public SocketClient(string ip, int port) { try { tcpSocket = new TcpClient(ip, port); Task.Factory.StartNew(new Action(() => { SocketUtility.SocketStreamReceive(tcpSocket, MessageReceiveHandler); })); } catch (Exception e) { OnExceptionReceive?.Invoke(e.Message); } }
private void manageMiddlewareRead() { var stream = _middleware.GetStream(); try { OnMiddlewareConnected?.Invoke("Connected to Middleware"); SocketUtility.SocketStreamReceive(_middleware, HandleMessage); } catch (Exception e) { OnExceptionReceive?.Invoke(e.Message); OnMiddlewareConnected?.Invoke("Discnnected from Middleware"); } _listener.BeginAcceptTcpClient(beginAcceptTcpClient, null); }
private void beginAcceptTcpClient(IAsyncResult ar) { TcpClient client = serverListener.EndAcceptTcpClient(ar); clientListener.BeginAcceptTcpClient(beginAcceptTcpClient, null); clients.Add(client); OnClientConnected?.Invoke(client.Client.RemoteEndPoint.AddressFamily.ToString()); try { SocketUtility.SocketStreamReceive(client, ClientHandleMessage); } catch (Exception e) { OnExceptionReceive?.Invoke(e.Message); OnClientDisconnected?.Invoke(client.Client.RemoteEndPoint.AddressFamily.ToString()); clients.Remove(client); } }
private void beginAcceptTcpServer(IAsyncResult ar) { TcpClient server = serverListener.EndAcceptTcpClient(ar); serverListener.BeginAcceptTcpClient(beginAcceptTcpServer, null); servers.Add(server); OnServerConnected?.Invoke(server.Client.RemoteEndPoint.AddressFamily.ToString()); try { SocketUtility.SocketStreamReceive(server, ServerHandleMessage); } catch (Exception e) { OnExceptionReceive?.Invoke(e.Message); OnServerDisconnected?.Invoke(server.Client.RemoteEndPoint.AddressFamily.ToString()); servers.Remove(server); } }