Exemplo n.º 1
0
        public void WaitData(EndPoint clientEndPoint)
        {
            if (!ClientSockets.ContainsKey(clientEndPoint))
            {
                return;
            }

            TCPConnection client = ClientSockets[clientEndPoint];

            if (!client.Socket.Connected)
            {
                return;
            }


            try
            {
                client.Socket.BeginReceive(client.ReceiveBuffer, 0, client.ReceiveBuffer.Length,
                                           SocketFlags.None,
                                           new AsyncCallback(ReceiveCallBack), client);
            }
            catch (Exception ex)
            {
                //aqui es donde me da error constantemente
                OnException?.Invoke(ex); //Server Exception: An existing connection was forcibly closed by the remote host
            }
        }
Exemplo n.º 2
0
        public void SendData(EndPoint clientEndPoint, string data)
        {
            responseData = data;

            if (!ClientSockets.ContainsKey(clientEndPoint))
            {
                return;
            }

            if (data == "")
            {
                return;
            }


            //Socket socket = ClientSockets[clientEndPoint];
            TCPConnection client = ClientSockets[clientEndPoint];

            if (!client.Socket.Connected)
            {
                return;
            }


            //byte[] sendBufer = Encoding.ASCII.GetBytes(data);
            client.SendBufer = Encoding.ASCII.GetBytes(data);

            try
            {
                client.Socket.BeginSend(client.SendBufer, 0, client.SendBufer.Length,
                                        SocketFlags.None,
                                        new AsyncCallback(SendCallBack), client);
            }
            catch (Exception ex)
            {
                OnException?.Invoke(ex);
            }
        }