Пример #1
0
 /// <summary>
 /// 发送数据报文
 /// </summary>
 /// <param name="datagram"></param>
 public virtual void Send(string datagram)
 {
     try
     {
         if (datagram.Length == 0)
         {
             return;
         }
         if (!_isConnected)
         {
             //throw (new ApplicationException("没有连接服务器,不能发送数据"));
             DisConnectedServer(this, new NetEventArgs(_session));
             return;
         }
         //获得报文的编码字节
         byte[] data = _coder.GetEncodingBytes(datagram);
         _session.ClientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendDataEnd), _session.ClientSocket);
         System.Threading.Thread.Sleep(25);//每发送一次,需要作一下暂停
     }
     catch (Exception e)
     {
     }
 }
Пример #2
0
 /// <summary>
 /// 发送数据
 /// </summary>
 /// <param name="recvDataClient">接收数据的客户端会话</param>
 /// <param name="datagram">数据报文</param>
 public virtual void Send(Session recvDataClient, string datagram)
 {
     //获得数据编码
     byte[] data = _coder.GetEncodingBytes(datagram);
     recvDataClient.ClientSocket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendDataEnd), recvDataClient.ClientSocket);
 }