/// <summary> /// Tries to start the server /// </summary> public void Start() { try { _serverGuid = Guid.NewGuid(); _server = new BasicSocketServer(); _server.ReceiveMessageEvent += new ReceiveMessageDelegate(server_ReceiveMessageEvent); _server.ConnectionEvent += new SocketConnectionDelegate(server_ConnectionEvent); _server.CloseConnectionEvent += new SocketConnectionDelegate(server_CloseConnectionEvent); _server.Init(new IPEndPoint(IPAddress.Parse("127.0.0.1"), _port)); _server.StartUp(); _timer = new Timer(); _timer.Interval = _ping; _timer.Elapsed += _timer_Elapsed; _timer.Start(); RaiseNewTextEvent(string.Format("Server started on port {0}.", _port)); } catch (Exception ex) { RaiseNewTextEvent("Exception in Server.Start: " + ex.Message + "."); } }
//void keepAliveWorker_EvtSocketCheck(object sender) //{ //} public override bool start() { //Adding event handling methods, to handle the server messages _Server.ReceiveMessageEvent += new SocketServerLib.SocketHandler.ReceiveMessageDelegate(Server_DataReceived); _Server.ConnectionEvent += new SocketConnectionDelegate(Server_onConnection); _Server.CloseConnectionEvent += new SocketConnectionDelegate(Server_lostConnection); try { _Server.Init(new IPEndPoint(IPAddress.Any, _ListeningPort)); _Server.StartUp(); isServerStarted = true; worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.DoWork += worker_DoWork; worker.RunWorkerAsync(); } catch (Exception e) { Trace.WriteLine(e); return(false); } return(true); }