Пример #1
0
        private XmlReceiveDelegate xmlHandler; // Receive delegate when in xml mode

        #endregion Fields

        #region Constructors

        // Gets the underlying windows socket
        //public TcpClient Socket
        //{ get { return tcp; } }
        // C'tor
        public Client(IPAddress address, int port)
        {
            // Init fields
            this.port = port;
            this.address = address;
            tcp = new TcpClient(address.AddressFamily);
            handler = new Handler();
            xmlHandler = new XmlReceiveDelegate(handler.ReceiveMessage);
            // Create a remote call interface
            rpc = new XmlSenderStub(tcp);
        }
Пример #2
0
        private XmlReceiveDelegate _xmlHandler; // Receive delegate when in xml mode

        #endregion Fields

        #region Constructors

        // Indicates if this client is connected
        public Client(IPAddress address, int port)
        {
            // Init fields
            _port = port;
            _address = address;
            _tcp = new TcpClient(address.AddressFamily);
            _handler = new Handler();
            _xmlHandler = _handler.ReceiveMessage;
            // Create a remote call interface
            Rpc = new XmlSenderStub(_tcp);
        }
Пример #3
0
 // Handle an xml packet
 private void XmlReceive(int count)
 {
     // Look for a 0 at the end.
     for (int i = packetPos; i < packetPos + count; i++)
     {
         if (packet[i] == 0)
         {
             // Extract the xml
             string xml = System.Text.Encoding.UTF8.GetString(packet, 0, i);
             // Invoke the handler
             Program.Dispatcher.BeginInvoke(DispatcherPriority.Normal, xmlHandler, xml);
             // Switch to a binary handler if the message asked for it
             if (xml == "<Binary />")
             {
                 binHandler = new BinaryReceiveDelegate(handler.ReceiveMessage);
                 xmlHandler = null;
             }
             // Adjust the packet buffer
             count += packetPos - i - 1; packetPos = 0;
             Array.Copy(packet, i + 1, packet, 0, count);
             i = -1; continue;
         }
     }
     // Adjust the position in the packet buffer
     packetPos += count;
 }
Пример #4
0
 // Handle an xml packet
 private void XmlReceive(int count)
 {
     // Look for a 0 at the end.
     for (int i = _packetPos; i < _packetPos + count; i++)
     {
         if (_packet[i] != 0) continue;
         // Extract the xml
         string xml = Encoding.UTF8.GetString(_packet, 0, i);
         // Invoke the handler
         if (_xmlHandler != null)
             Program.Dispatcher.BeginInvoke(DispatcherPriority.Normal, _xmlHandler, xml);
         // Switch to a binary handler if the message asked for it
         if (xml == "<Binary />")
         {
             _binHandler = _handler.ReceiveMessage;
             _xmlHandler = null;
         }
         // Adjust the packet buffer
         count += _packetPos - i - 1;
         _packetPos = 0;
         Array.Copy(_packet, i + 1, _packet, 0, count);
         i = -1;
     }
     // Adjust the position in the packet buffer
     _packetPos += count;
 }