private void InitializeServer() { if (!_Settings.Ssl.Enable) { _TcpServer = new CavemanTcpServer( _Settings.Hostname, _Settings.Port); _Header = "[HttpServerLite http://" + _Settings.Hostname + ":" + _Settings.Port + "] "; } else { _TcpServer = new CavemanTcpServer( _Settings.Hostname, _Settings.Port, _Settings.Ssl.Enable, _Settings.Ssl.PfxCertificateFile, _Settings.Ssl.PfxCertificatePassword); _Header = "[HttpServerLite https://" + _Settings.Hostname + ":" + _Settings.Port + "] "; } _TcpServer.Settings.MonitorClientConnections = false; _TcpServer.Events.ClientConnected += ClientConnected; _TcpServer.Events.ClientDisconnected += ClientDisconnected; if (_Settings.Debug.Tcp) { _TcpServer.Logger = _Events.Logger; } }
/// <summary> /// Tear down the server and dispose of background workers. /// Do not use the object after disposal. /// </summary> /// <param name="disposing">Indicate if resources should be disposed.</param> protected virtual void Dispose(bool disposing) { if (disposing) { Events.HandleServerDisposing(this, EventArgs.Empty); if (_TcpServer != null) { if (_TcpServer.IsListening) { Stop(); } _TcpServer.Dispose(); _TcpServer = null; } if (_TokenSource != null && !_Token.IsCancellationRequested) { _TokenSource.Cancel(); } _Statistics = null; _Settings = null; _Routes = null; _Events = null; } }
// Server private void Server_Start(object sender, RoutedEventArgs e) { server = new CavemanTcpServer(ServerIP.Text + ":11500"); server.Events.ClientConnected += Events_ServerClientConnected; server.Events.ClientDisconnected += Events_ServerClientDisconnected; server.Start(); Application.Current.Dispatcher.Invoke(() => ClientTextBlock.Text += "Server started.\n"); }
public HttpServer(int port) { _Port = port; _Token = _TokenSource.Token; _TcpServer = new CavemanTcpServer("127.0.0.1", _Port); _TcpServer.Settings.MonitorClientConnections = false; _TcpServer.Events.ClientConnected += ClientConnected; _TcpServer.Events.ClientDisconnected += ClientDisconnected; }
public TransferServer(IPAddress systemIP, int port, int maxPingMs, int maxBufferSize, IProgress <TransferProgressReport> transferProgress) { this.maxPingMs = maxPingMs; this.maxBufferSize = maxBufferSize; this.transferProgress = transferProgress; server = new CavemanTcpServer(systemIP.ToString(), port); server.Events.ClientConnected += Events_ClientConnected; server.Events.ClientDisconnected += Events_ClientDisconnected; server.Keepalive.EnableTcpKeepAlives = true; server.Keepalive.TcpKeepAliveInterval = 5; server.Keepalive.TcpKeepAliveTime = 5; server.Keepalive.TcpKeepAliveRetryCount = 5; }
static void InitializeServer() { _Server = new CavemanTcpServer("127.0.0.1", 8000, false, null, null); _Server.Logger = Logger; _Server.Events.ClientConnected += (s, e) => { Console.WriteLine("Client " + e.IpPort + " connected to server"); _LastClient = e.IpPort; }; _Server.Events.ClientDisconnected += (s, e) => { Console.WriteLine("Client " + e.IpPort + " disconnected from server"); }; }
static void InitializeServer() { // _Server = new CavemanTcpServer("*", 8000, false, null, null); _Server = new CavemanTcpServer("0.0.0.0:8000"); _Server.Logger = Logger; _Server.Settings.MonitorClientConnections = true; _Server.Events.ClientConnected += (s, e) => { Console.WriteLine("Client " + e.IpPort + " connected to server"); _LastClient = e.IpPort; }; _Server.Events.ClientDisconnected += (s, e) => { Console.WriteLine("Client " + e.IpPort + " disconnected from server"); }; }
static void StartEchoServer() { Console.WriteLine("[Server] starting TCP/9000"); _Server = new CavemanTcpServer("127.0.0.01", 9000, false, null, null); _Server.Events.ClientConnected += (s, e) => { _LastIpPort = e.IpPort; Console.WriteLine("[Server] " + e.IpPort + " connected"); }; _Server.Events.ClientDisconnected += (s, e) => { _LastIpPort = null; Console.WriteLine("[Server] " + e.IpPort + " disconnected"); }; _Server.Logger = Console.WriteLine; _Server.Start(); Console.WriteLine("[Server] started TCP/9000"); while (true) { if (String.IsNullOrEmpty(_LastIpPort)) { Task.Delay(100).Wait(); continue; } ReadResult rr = _Server.Read(_LastIpPort, 10); if (rr.Status == ReadResultStatus.Success) { Console.WriteLine("[Server] received " + Encoding.UTF8.GetString(rr.Data)); WriteResult wr = _Server.Send(_LastIpPort, "serverecho"); } } }
static void InitializeServer() { _Server = new CavemanTcpServer(_Hostname, _Port); _Server.Settings.MonitorClientConnections = false; _Server.Events.ClientConnected += ClientConnected; }
public void Stop() { server.Stop(); server.Dispose(); server = null; }