示例#1
0
        private void ReceivedBytes(byte[] bytes, ReceivedBytesEventArgs args)
        {
            if (args.State == EventStates.Success)
            {
                ClientInfo newClientInfo = serializer.DeserializeXmlFromBytes<ClientInfo>(bytes);

                if (!newClientInfo.IpAddress.Equals(AndroidClient.Me.IpAddress))
                {
                    if (args.ConnectionType == ConnectionTypes.Udp)
                    {
                        byte[] msg = serializer.SerializeXmlToBytes(AndroidClient.Me);
                        AndroidClient.SendTcp(newClientInfo, msg);
                    }
                    else if (args.ConnectionType == ConnectionTypes.Tcp)
                    {
                        AndroidClient.AddClientInfo(newClientInfo);
                        RunOnUiThread(() => listAdapter.Add(newClientInfo.Name));
                    }
                }
            }
            else
            {
                throw new Exception(args.ErrorMessage);
            }
        }
示例#2
0
        private void ReceivedBytes(byte[] bytes, ReceivedBytesEventArgs args)
        {
            if (args.State == EventStates.Success)
            {
                var newClientInfo = _serializer.DeserializeXmlFromBytes<ClientInfo>(bytes);

                 if (!newClientInfo.IpAddress.Equals(WindowsClient.Me.IpAddress))
                 {
                    //Receive information about devices.
                    if (args.ConnectionType == ConnectionTypes.Tcp)
                    {
                        WindowsClient.AddClientInfo(newClientInfo);
                    }
                    //Respond to request from device for your information.
                    else if (args.ConnectionType == ConnectionTypes.Udp)
                    {
                        var msg = _serializer.SerializeXmlToBytes(WindowsClient.Me);
                        WindowsClient.SendTcp(newClientInfo, msg);
                    }
                }
            }
            else
            {
                throw new Exception(args.ErrorMessage);
            }
        }
示例#3
0
文件: Server.cs 项目: fcin/RemindMe
        private void ListenerConnectionReceived(object sender, TcpSocketListenerConnectEventArgs e)
        {
            var client = (TcpSocketClient)e.SocketClient;
            var bytes = new List<byte>();

            while (true)
            {
                int nextByte = ReadByte(client);
                if (nextByte == -1)
                    break;

                bytes.Add((byte)nextByte);
            }

            if (ReceivedBytes != null)
            {
                var eventArgs = new ReceivedBytesEventArgs
                {
                    ConnectionType = ConnectionTypes.Tcp
                };
                ReceivedBytes(bytes.ToArray(), eventArgs);
                bytes.Clear();
            }
        }
示例#4
0
文件: Server.cs 项目: fcin/RemindMe
 private void MessageReceived(object sender, UdpSocketMessageReceivedEventArgs e)
 {
     if (ReceivedBytes != null)
     {
         var eventArgs = new ReceivedBytesEventArgs { ConnectionType = ConnectionTypes.Udp };
         ReceivedBytes(e.ByteData, eventArgs);
     }
 }