public async Task ServerOpen(int serverPort) { _isStopping = false; _socketTcpServer = new StreamSocketListener(); _socketTcpServer.Control.KeepAlive = false; _socketTcpServer.Control.NoDelay = true; _socketTcpServer.ConnectionReceived += SocketTcpServerConnectionReceived; try { //start log session _logJson = new LoggingToTxt(); //Enable tcplistener await _socketTcpServer.BindServiceNameAsync(serverPort.ToString()); PrintServerSideMessage("Server started..."); } catch (Exception e) { PrintServerSideMessage("Can't start server!\r\n" + e.ToString()); } }
public void StopServer() { _isStopping = true; try { //zamknij wszystkie sockety(muszą dostać informacje o disconnect) for (int i = 0; i < _socketsix.Count; i++) { _dataReaderix[i].Dispose(); _socketsix[i].Dispose(); } _socketsix?.Clear(); _dataReaderix?.Clear(); _socketsIpix?.Clear(); ToLbConSockIp?.Invoke(this, new ListWrite(_socketsIpix)); PrintServerSideMessage("Server closed."); _socketTcpServer.Dispose(); _logJson = null; } catch (Exception e) { PrintServerSideMessage("Server error during closing." + e.ToString()); } }