Ejemplo n.º 1
0
        public bool Connect()
        {
            if (Opened)
            {
                return(true);
            }

            using (var runonce = CriticalSectionHelper.RunOnce(_connecting))
            {
                if (!runonce.Run)
                {
                    return(true);
                }

                _socket = CreateSocket();
                try
                {
                    _socket.Connect(Host, Port);
                }
                catch (Exception ex)
                {
                    TraceUtil.Error("Socket Connect error", ex);
                    NotifSender.SendNotif(Id, NetworkErrorCode, Protocol);
                    return(false);
                }

                _socketDataReceiver.Receive(_socket, DataReceivedHandler, Close);
            }

            _opened.Set();

            return(true);
        }
Ejemplo n.º 2
0
 protected void SendTcpNotif(int sessionId, TcpNotifCode tcpNotif)
 {
     if (tcpNotif != TcpNotifCode.OK)
     {
         NotifSender.SendTcpNotif(sessionId, tcpNotif);
     }
 }
Ejemplo n.º 3
0
 public void EndSend()
 {
     if (BytesToWrite > BytesSent)
     {
         TraceUtil.Warn("Data sent ok but more or less data are expected. Session Id: {0}, Protocol: {1}, Bytes to send: {2}, Bytes sent: {3}", Id, Protocol, BytesToWrite, BytesSent);
         NotifSender.SendNotif(Id, WaitMoreOrLessDataCode, Protocol);
     }
     //BytesSent = 0;
     //BytesToWrite = 0;
 }
Ejemplo n.º 4
0
        protected IUdpSession GetUdpSession(int sessionId)
        {
            var session = SessionManager.GetSession(sessionId);

            if (session == null)
            {
                NotifSender.SendUdpNotif(sessionId, UdpNotifCode.BadSessionId);
                return(null);
            }

            return((IUdpSession)session);
        }
Ejemplo n.º 5
0
        public virtual bool Send(byte[] data)
        {
            if (!Opened)
            {
                NotifSender.SendNotif(Id, NetworkErrorCode, Protocol);
                return(false);
            }

            BytesSent += data.Length;
            _socket.Send(data);

            TraceUtil.Info("Data sent to remote({0}: {1}): {2} {3}", Host, Port, data.ToHexString(0, data.Length),
                           data.InterpretAsString(0, data.Length));

            return(true);
        }
Ejemplo n.º 6
0
 protected void SendNotif(int sessionId, int notifCode, DataProtocol protocol)
 {
     NotifSender.SendNotif(sessionId, notifCode, protocol);
 }