Exemplo n.º 1
0
        public void YM_SendMessage(List <Object> infolist)
        {
            //获取socket
            Socket sendSocket = GetUdpSocket();
            //获取对方 ip port
            EndPoint youPoint = GetYouUdpPoint() as EndPoint;

            //将数据转换为byte[]
            byte[] dataSe = ClassSerializers.Serializebinary(infolist).ToArray();
            //发送数据
            sendSocket.SendTo(dataSe, youPoint);
            //关闭Socket
            sendSocket.Close();
        }
Exemplo n.º 2
0
 public List <Object> LR_ActionSend_Receive(List <Object> infolist)
 {
     try
     {
         Byte[]        dataReceive = new Byte[1024]; //存放接收数据
         List <Object> dataRece    = null;           //反序列化后的数据
         client.Connect(GetTcpPoint());              //连接服务器
         if (client.Connected)
         {
             byte[] data = ClassSerializers.Serializebinary(infolist).ToArray();
             client.Send(data, data.Length, 0);
             client.Receive(dataReceive, dataReceive.Length, 0);   //接收数据    //在这等着呢 -_-
             dataRece = ClassSerializers.DeSerializebinary(new MemoryStream(dataReceive)) as List <Object>;
         }
         client.Close();
         return(dataRece);
     }
     catch
     {
         return(null);
     }
 }