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

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


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

            var tcpClient = new TcpClient();
            await tcpClient.ConnectAsync(_ipEndPoint.Address, _ipEndPoint.Port);

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

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

            return(connection);
        }