Пример #1
0
        // ---------------------------------------------------------------
        private static void OnBeginReceive(IAsyncResult result)
        {
            try
            {
                Socket client = (Socket)result.AsyncState;
                int bytesRead = client.EndReceive(result);
                string response = ByteToString(_buffer);

                Packet receivedPacket = new Packet();

                receivedPacket.XmlDocument = XDocument.Parse(response, LoadOptions.None);
                PacketReceivedCallback(receivedPacket);

                _buffer = new byte[10000];

                ClientSocket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None,
                        new AsyncCallback(OnBeginReceive), ClientSocket);

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Пример #2
0
 // ---------------------------------------------------------------
 public static void Send(Packet core)
 {
     string message = core.RawXml;
     byte[] buffer = StringToByte(message);
     ClientSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, OnBeginSend, ClientSocket);
 }