/// <summary> /// 簡易サーバーを開始 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void clickStartServer(object sender, RoutedEventArgs e) { this.textIP.Text = NetworkPresenter.GetCurrentIpv4Address(); _server = new SimpleWebServer(); _server.OnReceived += _server_OnReceived; _server.Start(); }
static void Main(string[] args) { _rand = new Random(Environment.TickCount); SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += WebServerOnConnect; _webServer.onData += WebServerOnData; _webServer.onDisconnect += WebServerOnDisconnect; Timer stateUpdateTimer = new Timer(1f / Constants.SERVER_TICKRATE * 1000); stateUpdateTimer.Elapsed += StateUpdateTimerOnElapsed; stateUpdateTimer.AutoReset = true; stateUpdateTimer.Enabled = true; while (!Console.KeyAvailable) { _webServer.ProcessMessageQueue(); switch (_currentState) { case GameState.Waiting: { if (_connectedIds.Count >= 2) { _currentState = GameState.Begin; SendStateUpdate(_currentState); } break; } case GameState.Begin: { // Set timer to go to builder state Timer beginTimer = new Timer(SECONDS_WAITING_IN_BEGIN * 1000); beginTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _currentState = GameState.Builder; SendStateUpdate(_currentState); }; break; } case GameState.Builder: { } } } Console.WriteLine("Closing server"); _webServer.Stop(); }
static void Main(string[] args) { SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += WebServerOnConnect; _webServer.onData += WebServerOnData; _webServer.onDisconnect += WebServerOnDisconnect; Timer stateUpdateTimer = new Timer(1f / Constants.SERVER_TICKRATE * 1000); stateUpdateTimer.Elapsed += StateUpdateTimerOnElapsed; stateUpdateTimer.AutoReset = true; stateUpdateTimer.Enabled = true; while (!Console.KeyAvailable) { _webServer.ProcessMessageQueue(); } Console.WriteLine("Closing server"); _webServer.Stop(); }
private void InitializeWebServer() { httpserver = new SimpleWebServer(6010); httpserver.SetFileDir("GUI"); httpserver.SetDefaultPage("index.html"); httpserver.Start(); }
static void Main(string[] args) { SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += delegate(int i) { Console.WriteLine($"Client {i} joined, sending hello"); byte[] buff = System.Text.Encoding.UTF8.GetBytes("Hello from server"); _webServer.SendOne(i, new ArraySegment <byte>(buff)); }; _webServer.onData += delegate(int i, ArraySegment <byte> data) { string msg = System.Text.Encoding.UTF8.GetString(data.Array); Console.WriteLine($"Client {i} send: {msg}"); }; while (!Console.KeyAvailable) { _webServer.ProcessMessageQueue(); } Console.WriteLine("Closing server"); _webServer.Stop(); }
// Start is called before the first frame update void Start() { _timeSinceLastSend = Time.time; _playerTransforms = new Dictionary <ushort, uint[]>(); _connectionIds = new List <int>(); SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); if (Application.isBatchMode) { Debug.Log("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); } else { Debug.Log("Setting up non secure server"); sslConfig = new SslConfig(false, "", "", SslProtocols.Tls12); } _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Debug.Log("Server started"); _webServer.onConnect += WebServerOnonConnect; _webServer.onData += WebServerOnonData; _webServer.onError += delegate(int i, Exception exception) { Debug.Log("Error: " + exception.Message); }; _webServer.onDisconnect += WebServerOnonDisconnect; }
static void Main(string[] args) { var server = new SimpleWebServer("http://localhost:8080/", "files/"); server.Start(); Console.WriteLine("Press key to exit ..."); Console.Read(); }
static void Main(string[] args) { SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); }
static void Main(string[] args) { SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += delegate(int i) { Console.WriteLine($"Client {i} joined, sending hello"); } }
static void Main(string[] args) { SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += delegate(int i) { Console.WriteLine($"Client {i} joined, sending hello"); byte[] buff = System.Text.Encoding.UTF8.GetBytes("Hello from server"); _webServer.SendOne(i, new ArraySegment <byte>(buff)); }; }
static void Main(string[] args) { string baseDir = GetBaseDirectory(); FileQueryDispatcher files = new FileQueryDispatcher(Path.Combine(baseDir, @"..\..\www"), "/"); DefaultQueryDispatcher root = new DefaultQueryDispatcher(Path.Combine(baseDir, @"..\..\www")); SimpleWebServer server = new SimpleWebServer(new ConsoleLogger()); server.Dispatchers.Add(root); server.Dispatchers.Add(files); server.Dispatchers.Add(new DemoData()); server.Dispatchers.Add(new PageNotFoundQueryDispatcher()); server.Port = 8080; server.IPAddress = IPAddress.Any; server.Start(); Console.ReadLine(); server.Stop(); }
private IEnumerator Start() { var tcpConfig = new TcpConfig(true, 5000, 5000); server = new SimpleWebServer(5000, tcpConfig, 32000, 5000, default); server.Start(7776); server.onConnect += (id) => { connection = true; Debug.Log($"New Client connected, id:{id}"); }; server.onDisconnect += (id) => Debug.Log($"Client disconnected, id:{id}"); server.onData += OnData; server.onError += (id, exception) => Debug.Log($"Error because of Client, id:{id}, Error:{exception}"); yield return(new WaitUntil(() => connection)); for (int i = 1; i < 200; i++) { yield return(Send(i * 1000)); } }
private async Task ServerServer() { try { // create server instance var tcpConfig = new TcpConfig(noDelay: false, sendTimeout: 5000, receiveTimeout: 20000); var server = new SimpleWebServer(5000, tcpConfig, ushort.MaxValue, 5000, new SslConfig()); // listen for events server.onConnect += (id) => Debug.Log($"New Client connected, id:{id}"); server.onDisconnect += (id) => Debug.Log($"Client disconnected, id:{id}"); server.onData += (id, data) => { Debug.Log($"Data from Client, id:{id}, {BitConverter.ToString(data.Array, data.Offset, data.Count)}"); // pong server.SendOne(id, data); }; server.onError += (id, exception) => Debug.Log($"Error because of Client, id:{id}, Error:{exception}"); // start server listening on port 7777 server.Start(7777); while (true) { server.ProcessMessageQueue(); await Task.Yield(); if (token.stop) { break; } } token = null; } catch (Exception e) { Debug.LogException(e); } }
static void Main(string[] args) { SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += WebServerOnConnect; _webServer.onData += WebServerOnData; while (!Console.KeyAvailable) { _webServer.ProcessMessageQueue(); } Console.WriteLine("Closing server"); _webServer.Stop(); }
static void Main(string[] args) { _rand = new Random(Environment.TickCount); SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += WebServerOnConnect; _webServer.onData += WebServerOnData; _webServer.onDisconnect += WebServerOnDisconnect; Timer stateUpdateTimer = new Timer(1f / Constants.SERVER_TICKRATE * 1000); stateUpdateTimer.Elapsed += StateUpdateTimerOnElapsed; stateUpdateTimer.AutoReset = true; stateUpdateTimer.Enabled = true; while (!Console.KeyAvailable) { _webServer.ProcessMessageQueue(); // GUARD, DONT DO STATE STUFF IF WE ARE WAITING if (_waitingOnStateTimer) { continue; } switch (_currentState) { case GameState.Waiting: { if (_connectedIds.Count >= 2) { _currentState = GameState.Begin; SendStateUpdate(_currentState); } break; } case GameState.Begin: { // Set timer to go to builder state Timer beginTimer = new Timer(SECONDS_WAITING_IN_BEGIN * 1000); beginTimer.AutoReset = false; beginTimer.Start(); _waitingOnStateTimer = true; beginTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; _movedObjects = new List <ushort>(); _currentState = GameState.Builder; SendStateUpdate(_currentState); }; break; } case GameState.Builder: { // Set timer to go to builder state Timer buildTimer = new Timer(SECONDS_WAITING_IN_BUILD * 1000); buildTimer.AutoReset = false; buildTimer.Start(); _waitingOnStateTimer = true; buildTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; // Reset everyones guesses foreach (PlayerData playerData in _playerDatas.Values) { playerData.guesses.Clear(); } _currentState = GameState.Search; SendStateUpdate(_currentState); }; break; } case GameState.Search: { // Set timer to go to scoring state Timer searchTimer = new Timer(SECONDS_WAITING_IN_SEARCH * 1000); searchTimer.AutoReset = false; searchTimer.Start(); _waitingOnStateTimer = true; searchTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; _currentState = GameState.Scoring; SendStateUpdate(_currentState); }; break; } case GameState.Scoring: { foreach (var playerPair in _playerDatas) { } } } } Console.WriteLine("Closing server"); _webServer.Stop(); }
static void Main(string[] args) { logger.Info("Starting!"); TheSockets sockets = new TheSockets(); SimpleWebServer nws = new SimpleWebServer(4567); nws.Start(); InfluxConnection c = new InfluxConnection(); c.URL = "http://localhost:8086/"; // HttpInfluxDB db = new HttpInfluxDB(c); // db.CreateDatabase("influxdays"); // sockets.influx = new HttpInfluxWriter(db, "influxdays", 50000); foreach (var d in HidSharp.DeviceList.Local.GetHidDevices()) { logger.Info("DEVICE: " + d.DevicePath); try { logger.Info(" > " + d.GetFriendlyName()); } catch { } } DeviceWatcher watcherSide = null; DeviceWatcher watcherWheel = null; HidSharp.HidDevice dev = DeviceWatcher.find("Saitek Side Panel Control Deck"); if (dev != null) { watcherSide = new DeviceWatcher("panel_", dev, sockets); } dev = DeviceWatcher.find("Saitek Heavy Eqpt. Wheel & Pedal"); if (dev != null) { watcherWheel = new DeviceWatcher("wheel_", dev, sockets); } WebSocketServer server = new WebSocketServer("ws://0.0.0.0:8181"); server.RestartAfterListenError = true; server.Start(socket => { socket.OnOpen = () => { sockets.open.Add(socket); logger.Info("WebSocket Open! " + sockets.open.Count); if (watcherSide != null) { watcherSide.broadcast(); } if (watcherWheel != null) { watcherWheel.broadcast(); } }; socket.OnClose = () => { sockets.open.Remove(socket); logger.Info("WebSocket Remove! " + sockets.open.Count); }; socket.OnMessage = message => logger.Info("WebSocket: " + message); }); while (true) { var x = Console.ReadLine(); Console.WriteLine("ECHO: " + x); } }
static void Main(string[] args) { _rand = new Random(Environment.TickCount); SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += WebServerOnConnect; _webServer.onData += WebServerOnData; _webServer.onDisconnect += WebServerOnDisconnect; Timer stateUpdateTimer = new Timer(1f / Constants.SERVER_TICKRATE * 1000); stateUpdateTimer.Elapsed += StateUpdateTimerOnElapsed; stateUpdateTimer.AutoReset = true; stateUpdateTimer.Enabled = true; while (!Console.KeyAvailable) { _webServer.ProcessMessageQueue(); // GUARD, DONT DO STATE STUFF IF WE ARE WAITING if (_waitingOnStateTimer) { continue; } switch (_currentState) { case GameState.Waiting: { if (_handshakenClientCount >= 2 && _connectedIds.Count >= 2) { _currentState = GameState.Begin; SendStateUpdate(_currentState); } break; } case GameState.Begin: { // Set timer to go to builder state beginTimer = new Timer(SECONDS_WAITING_IN_BEGIN * 1000); beginTimer.AutoReset = false; beginTimer.Start(); _waitingOnStateTimer = true; beginTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; _movedObjects = new Dictionary <ushort, Tuple <ushort, ushort> >(); _currentState = GameState.Builder; SendStateUpdate(_currentState); }; break; } case GameState.Builder: { // Set timer to go to builder state buildTimer = new Timer(SECONDS_WAITING_IN_BUILD * 1000); buildTimer.AutoReset = false; buildTimer.Start(); _waitingOnStateTimer = true; buildTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; // Reset everyones guesses foreach (PlayerData playerData in _playerDatas.Values) { playerData.guesses.Clear(); } // Make sure builder actually moved something, // if he didnt, goto scoring and give everyone else a point if (_movedObjects.Count > 0) { _currentState = GameState.Search; } else { foreach (PlayerData data in _playerDatas.Values) { if (data.id != _builderId) { data.points += 1; } _playerDatas[_builderId].points -= (ushort)_handshakenClientCount; } _currentState = GameState.Scoring; } SendStateUpdate(_currentState); }; break; } case GameState.Search: { // Set timer to go to scoring state searchTimer = new Timer(SECONDS_WAITING_IN_SEARCH * 1000); searchTimer.AutoReset = false; searchTimer.Start(); _waitingOnStateTimer = true; searchTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; _currentState = GameState.Scoring; SendStateUpdate(_currentState); }; break; } case GameState.Scoring: { // Set timer to wait for points to come in from clients scoringTimer = new Timer(SECONDS_WAITING_IN_SCORING * 1000); scoringTimer.AutoReset = false; scoringTimer.Start(); _waitingOnStateTimer = true; scoringTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; // Tell everyone everyones scores _bitBuffer.Clear(); _bitBuffer.AddByte(7); _bitBuffer.AddUShort((ushort)_playerDatas.Count); foreach (PlayerData data in _playerDatas.Values) { _bitBuffer.AddUShort(data.id); _bitBuffer.AddShort(data.points); } _bitBuffer.ToArray(_buffer); _webServer.SendAll(_connectedIds, new ArraySegment <byte>(_buffer, 0, 3 + 4 * _playerDatas.Count)); if (_handshakenClientCount >= 2 && _connectedIds.Count >= 2) { _currentState = GameState.Begin; } else { _currentState = GameState.Waiting; } SendStateUpdate(_currentState); }; break; } } } Console.WriteLine("Closing server"); _webServer.Stop(); }
static void Main(string[] args) { _rand = new Random(Environment.TickCount); SslConfig sslConfig; TcpConfig tcpConfig = new TcpConfig(true, 5000, 20000); Console.WriteLine("Setting up secure server"); sslConfig = new SslConfig(true, "cert.pfx", "", SslProtocols.Tls12); _webServer = new SimpleWebServer(10000, tcpConfig, 16 * 1024, 3000, sslConfig); _webServer.Start(Constants.GAME_PORT); Console.WriteLine("Server started"); _webServer.onConnect += WebServerOnConnect; _webServer.onData += WebServerOnData; _webServer.onDisconnect += WebServerOnDisconnect; Timer stateUpdateTimer = new Timer(1f / Constants.SERVER_TICKRATE * 1000); stateUpdateTimer.Elapsed += StateUpdateTimerOnElapsed; stateUpdateTimer.AutoReset = true; stateUpdateTimer.Enabled = true; while (!Console.KeyAvailable) { _webServer.ProcessMessageQueue(); // GUARD, DONT DO STATE STUFF IF WE ARE WAITING if (_waitingOnStateTimer) { continue; } switch (_currentState) { case GameState.Waiting: { if (_connectedIds.Count >= 2) { _currentState = GameState.Begin; SendStateUpdate(_currentState); } break; } case GameState.Begin: { // Set timer to go to builder state beginTimer = new Timer(SECONDS_WAITING_IN_BEGIN * 1000); beginTimer.AutoReset = false; beginTimer.Start(); _waitingOnStateTimer = true; beginTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; _movedObjects = new List <ushort>(); _currentState = GameState.Builder; SendStateUpdate(_currentState); }; break; } case GameState.Builder: { // Set timer to go to builder state buildTimer = new Timer(SECONDS_WAITING_IN_BUILD * 1000); buildTimer.AutoReset = false; buildTimer.Start(); _waitingOnStateTimer = true; buildTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; // Reset everyones guesses foreach (PlayerData playerData in _playerDatas.Values) { playerData.guesses.Clear(); } _currentState = GameState.Search; SendStateUpdate(_currentState); }; break; } case GameState.Search: { // Set timer to go to scoring state searchTimer = new Timer(SECONDS_WAITING_IN_SEARCH * 1000); searchTimer.AutoReset = false; searchTimer.Start(); _waitingOnStateTimer = true; searchTimer.Elapsed += delegate(Object source, ElapsedEventArgs e) { _waitingOnStateTimer = false; _currentState = GameState.Scoring; SendStateUpdate(_currentState); }; break; } case GameState.Scoring: { short builderPoints = 0; _bitBuffer.Clear(); _bitBuffer.AddByte(7); _bitBuffer.AddUShort((ushort)_playerDatas.Count); foreach (var playerData in _playerDatas.Values) { // GUARD, DON'T SCORE THE BUILDER THIS WAY if (playerData.id == _builderId) { continue; } // Free points for objects builder couldnt move // A point for a correct guess, minus point for a wrong guess int numCorrect = _movedObjects.Distinct().Intersect(playerData.guesses).Count(); int newPoints = (numCorrect * 2) - playerData.guesses.Count + (NUMBER_OF_MOVEABLE_OBJECTS - _movedObjects.Count); playerData.points += (short)newPoints; // Builder gets a point for each player who couldnt find any differences if (numCorrect == 0) { builderPoints += 1; } _bitBuffer.AddUShort(playerData.id); _bitBuffer.AddShort(playerData.points); } _playerDatas[_builderId].points += builderPoints; _bitBuffer.AddUShort((ushort)_builderId); _bitBuffer.AddShort(_playerDatas[_builderId].points); _bitBuffer.ToArray(_buffer); _webServer.SendAll(_connectedIds, new ArraySegment <byte>(_buffer, 0, 3 + 2 * _playerDatas.Count)); if (_connectedIds.Count >= 2) { _currentState = GameState.Begin; } else { _currentState = GameState.Waiting; } SendStateUpdate(_currentState); break; } } } Console.WriteLine("Closing server"); _webServer.Stop(); }