Beispiel #1
0
        public ClientTcpSocket(ISocketLog log, IPEndPoint ipEndPoint, int reconnectTimeOut, Func <TService> srvFactory)
        {
            SocketStatistic   = new SocketStatistic();
            _log              = log;
            _ipEndPoint       = ipEndPoint;
            _reconnectTimeOut = reconnectTimeOut;

            _srvFactory = srvFactory;
        }
        public ServerTcpSocket(IPEndPoint ipEndPoint, ISocketLog log, Func <TService> srvFactory)
        {
            _srvFactory  = srvFactory;
            _ipEndPoint  = ipEndPoint;
            Log          = log;
            _connections = new Connections(log);


            SocketStatistic = new SocketStatistic();
        }
Beispiel #3
0
 public ClientTcpSocket(
     ILogFactory logFactory,
     MeClientSettings settings,
     Func <TService> srvFactory)
 {
     SocketStatistic     = new SocketStatistic();
     _logFactory         = logFactory;
     _log                = logFactory.CreateLog(this);
     _ipEndPoint         = settings.Endpoint;
     _reconnectTimeOut   = (int)settings.ReconnectTimeOut.TotalMilliseconds;
     _pingInterval       = (int)settings.PingInterval.TotalSeconds;
     _disconnectInterval = (int)settings.DisconnectInterval.TotalSeconds;
     _srvFactory         = srvFactory;
 }
Beispiel #4
0
        public ClientTcpSocket(
            ILogFactory logFactory,
            IPEndPoint ipEndPoint,
            int reconnectTimeOut,
            Func <TService> srvFactory)
        {
            SocketStatistic   = new SocketStatistic();
            _logFactory       = logFactory;
            _log              = logFactory.CreateLog(this);
            _ipEndPoint       = ipEndPoint;
            _reconnectTimeOut = reconnectTimeOut;

            _srvFactory = srvFactory;
        }
Beispiel #5
0
 public TcpConnection(
     ITcpService tcpService,
     ITcpSerializer tcpSerializer,
     TcpClient socket,
     SocketStatistic socketStatistic,
     ILogFactory logFactory,
     int id)
 {
     Id                                  = id;
     _tcpSerializer                      = tcpSerializer;
     _socket                             = socket;
     _socketStatistic                    = socketStatistic;
     _log                                = logFactory.CreateLog(this);
     _tcpService                         = tcpService;
     tcpService.SendDataToSocket         = SendDataToSocket;
     _socketStatistic.LastConnectionTime = DateTime.UtcNow;
 }
Beispiel #6
0
 public TcpConnection(
     ITcpService tcpService,
     ITcpSerializer tcpSerializer,
     TcpClient socket,
     SocketStatistic socketStatistic,
     ISocketLog log,
     int id)
 {
     Id                                  = id;
     _tcpSerializer                      = tcpSerializer;
     _socket                             = socket;
     _socketStatistic                    = socketStatistic;
     _legacyLog                          = log;
     _tcpService                         = tcpService;
     tcpService.SendDataToSocket         = SendDataToSocket;
     _socketStatistic.LastConnectionTime = DateTime.UtcNow;
 }
Beispiel #7
0
        // Метод, который пытается сделать соединение с сервером
        private async Task <TcpConnection> Connect()
        {
            _log?.Add("Attempt To Connect:" + _ipEndPoint.Address + ":" + _ipEndPoint.Port);

            var tcpClient = new TcpClient {
                NoDelay = true
            };
            await tcpClient.ConnectAsync(_ipEndPoint.Address, _ipEndPoint.Port);

            _service = _srvFactory();
            SocketStatistic.Init();
            var tcpSerializer = new TTcpSerializer();
            var connection    = new TcpConnection(_service, tcpSerializer, tcpClient, SocketStatistic, _log, _id++);

            _log?.Add("Connected. Id=" + connection.Id);

            return(connection);
        }