示例#1
0
        private void RequestMultiResponsesCallback(
            ServerConnectorContext serverConnectorContext, int module, int command, int requestId,
            object packet, bool isLast, int nReceived, int nTotal, Exception exception)
        {
            Console.WriteLine($"*********** RequestMultiResponsesCallback ************ requestId = {requestId}");

            var resBuf = ConnectorsUtils.SerializeMultiResponsePacket(
                ConnectorsUtils.RequestTypeRequestMultiResponses, module, command, packet, requestId, isLast, nReceived, nTotal);

            TcpSocketsUtils.Send(Socket, resBuf, OnSend, OnExcp);
        }
示例#2
0
        private void StartListeningBlocking()
        {
            IPEndPoint ep = new IPEndPoint(IPAddress.IPv6Any, _settings.ListenPort);

            _listenerSock = new Socket(
                IPAddress.IPv6Any.AddressFamily,
                SocketType.Stream,
                ProtocolType.Tcp);

            _listenerSock.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);

            _listenerSock.Bind(ep);
            _listenerSock.Listen(10);

            if (_keepAliveTimer == null)
            {
                _keepAliveTimer          = new System.Timers.Timer(_settings.KeepAliveTimerInterval * 1000);
                _keepAliveTimer.Elapsed += KeepAliveTimer_Elapsed;;
                _keepAliveTimer.Start();
            }

            new Thread(PacketsQueueWorker).Start();


            while (!_isDisposed)
            {
                try
                {
                    // Start an asynchronous socket to listen for connections.
                    Socket newSocket  = _listenerSock.Accept();
                    int    id         = _nextContextId++;
                    var    newContext = new ServerConnectorContext(id, this);
                    newContext.Socket = newSocket;
                    _contextMap[id]   = newContext;
                    OnNewConnector?.Invoke(newContext);
                    TcpSocketsUtils.Recv(
                        newSocket,
                        newContext.OnRecv,
                        newContext.OnExcp,
                        newContext.OnRecvProgress,
                        _settings.ReceiveBufferSize == 0 ? TcpSocketsUtils.ms_DefualtReceiveBufferSize : _settings.ReceiveBufferSize,
                        true);
                }
                catch (Exception ex)
                {
                    if (!_isDisposed)
                    {
                        OnException?.Invoke(null, ex);
                    }
                }
            }
        }
示例#3
0
        public static void SendMultiResponse <T>(this ServerConnectorContext serverConnectorContext, int module, int command, int requestId,
                                                 RequestMultiResponsesServerCallback callback, IMultiResponseListPacket <T> packet, List <T> list, int chunkSize = 1000)
        {
            var chunks = Split(list, chunkSize);

            int count = 0;

            foreach (var chunk in chunks)
            {
                packet.Records = chunk;
                count         += chunk.Count;

                callback(
                    serverConnectorContext, module, command, requestId,
                    packet,
                    count == list.Count,
                    count,
                    list.Count,
                    null);
            }
        }
示例#4
0
 internal void TriggerOnDebugLog(ServerConnectorContext serverConnectorContext, DebugLogType logType, string info)
 {
     OnDebugLog?.Invoke(serverConnectorContext, logType, info);
 }
示例#5
0
 internal void TriggerOnException(ServerConnectorContext serverConnectorContext, Exception ex)
 {
     OnException?.Invoke(serverConnectorContext, ex);
 }
示例#6
0
 internal void TriggerOnDisconnect(ServerConnectorContext serverConnectorContext)
 {
     OnDisconnect?.Invoke(serverConnectorContext);
 }
示例#7
0
 internal void TriggerOnRequestMultiResponsesPacket(
     ServerConnectorContext serverConnectorContext, int module, int command, int requestId, object packet,
     RequestMultiResponsesServerCallback callback)
 {
     OnRequestMultiResponses?.Invoke(serverConnectorContext, module, command, requestId, packet, callback);
 }
示例#8
0
 internal object TriggerOnRequestPacket(ServerConnectorContext serverConnectorContext, int module, int command, object packet)
 {
     return(OnRequestPacket?.Invoke(serverConnectorContext, module, command, packet));
 }
示例#9
0
 internal void TriggerOnPacket(ServerConnectorContext serverConnectorContext, int module, int command, object packet)
 {
     _packetsQueue.Add(new Tuple <ServerConnectorContext, int, int, object>(serverConnectorContext, module, command, packet));
 }