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); }
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); } } } }
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); } }
internal void TriggerOnDebugLog(ServerConnectorContext serverConnectorContext, DebugLogType logType, string info) { OnDebugLog?.Invoke(serverConnectorContext, logType, info); }
internal void TriggerOnException(ServerConnectorContext serverConnectorContext, Exception ex) { OnException?.Invoke(serverConnectorContext, ex); }
internal void TriggerOnDisconnect(ServerConnectorContext serverConnectorContext) { OnDisconnect?.Invoke(serverConnectorContext); }
internal void TriggerOnRequestMultiResponsesPacket( ServerConnectorContext serverConnectorContext, int module, int command, int requestId, object packet, RequestMultiResponsesServerCallback callback) { OnRequestMultiResponses?.Invoke(serverConnectorContext, module, command, requestId, packet, callback); }
internal object TriggerOnRequestPacket(ServerConnectorContext serverConnectorContext, int module, int command, object packet) { return(OnRequestPacket?.Invoke(serverConnectorContext, module, command, packet)); }
internal void TriggerOnPacket(ServerConnectorContext serverConnectorContext, int module, int command, object packet) { _packetsQueue.Add(new Tuple <ServerConnectorContext, int, int, object>(serverConnectorContext, module, command, packet)); }