예제 #1
0
        public static void SendAsDspMessage <T>(this NetworkStream s, T body) where T : struct
        {
            var msg = new DspMessage();

            msg.SetData <T>(body);
            var bytes = msg.ToBytes();

            s.Write(bytes, 0, bytes.Length);
        }
예제 #2
0
        public void Send(DspMessage msg)
        {
            try
            {
                //WriteLog("Send - Type:" + msg.Type + ", Size:" + msg.Size, LogLevel.Debug);
                //Debug.WriteLine("Send - Type:" + msg.Type + ", Size:" + msg.Size, LogLevel.Debug);
                tcp.Send(msg);
                //WriteLog("Sended - Type:" + msg.Type + ", Size:" + msg.Size);
                //Debug.WriteLine("Sended - Type:" + msg.Type + ", Size:" + msg.Size);
#if false
                //WriteLog("Send - Type:" + msg.Type + ", Size:" + msg.Size, LogLevel.Debug);
                //var buff = msg.ToBytes();
                //stream.Send(msg);
                if (socket.Poll(1000 * 100, SelectMode.SelectWrite))
                {
                    int sended = socket.Send(msg.ToBytes());
                    if (sended == 0)
                    {
                        //WriteLog("Send Fail. Disconnect");
                        Disconnect();
                    }
                }
                else
                {
                    Disconnect();
                }
                //WriteLog("Sended - Type:" + msg.Type + ", Size:" + msg.Size);
#endif
            }
            catch (Exception ex)
            {
                //WriteLog("Send Error - " + ex);
                Debug.WriteLine("Send Error - " + ex);
                //trace.Send("Error - " + ex);

                if (!IsConnected && Disconnected != null)
                {
                    Disconnected(this, null);
                }
            }
        }