예제 #1
0
        public bool Send(TcpClient client, ProtoMsg frame)
#endif
        {
            if (client == null)
            {
                return(false);
            }

            //确保我们没有写入同一个客户端的竞争条件
            // Make sure that we don't have any race conditions with writing to the same client
            lock (client)
            {
                try
                {
                    //从帧中获取原始字节并发送
                    // Get the raw bytes from the frame and send them
                    byte[] data = frame.GetData();

                    RawWrite(client, data);
                    return(true);
                }
                catch
                {
                    //客户端不再连接或无响应
                    // The client is no longer connected or is unresponsive
                }
            }

            return(false);
        }
예제 #2
0
 /// <summary>
 /// The direct byte send method to the specified client
 /// </summary>
 /// <param name="client">The target client that will receive the frame</param>
 /// <param name="frame">The frame that is to be sent to the specified client</param>
 /// <summary>
 ///直接字节发送方法到指定的客户端
 /// </ summary>
 /// <param name =“client”>将接收帧的目标客户端</ param>
 /// <param name =“frame”>要发送到指定客户端的帧</ param>
 public virtual void Send(ProtoMsg frame)
 {
     //确保我们没有写入同一个客户端的竞争条件
     // Make sure that we don't have any race conditions with writing to the same client
     lock (client)
     {
         //从帧中获取原始字节并发送
         // Get the raw bytes from the frame and send them
         byte[] data = frame.GetData();
         RawWrite(data);
     }
 }