/// <summary> /// Connect the server with the specified IP and port. /// </summary> /// <param name="ip">IP of host server.</param> /// <param name="port">Port of host server.</param> public void Connect(string ip, int port) { _server = new PlanetServer(); // add handlers for basic actions _server.EventDispatcher.ConnectionEvent += OnConnection; _server.EventDispatcher.ConnectionLostEvent += OnConnectionLost; _server.EventDispatcher.PublicMessageEvent += OnPublicMessage; _server.Connect(ip, port); }
void OnApplicationQuit() { if (_server != null) { // remove event handlers _server.EventDispatcher.ConnectionLostEvent -= OnConnectionLost; _server.EventDispatcher.ExtensionEvent -= OnResponse; _server.EventDispatcher.PublicMessageEvent -= OnPublicMessage; // tell the server to disconnect this user so it isn't hanging around _server.Disconnect(); _server = null; } }
public ServerTest() { _server = new PlanetServer(); _server.EventDispatcher.ConnectionEvent += OnConnection; _server.EventDispatcher.ConnectionLostEvent += OnConnectionLost; _server.EventDispatcher.LoginEvent += OnLogin; _server.EventDispatcher.ExtensionEvent += OnResponse; _server.Connect("127.0.0.1", 8000); ServerThread worker = new ServerThread(_server); Thread thread = new Thread(worker.Update); while (!thread.IsAlive) { worker.Update(); Thread.Sleep(1); } }
public ServerThread(PlanetServer server) { _server = server; }