public void TestSocketProtocol() { XPloitSocketProtocol proto = new XPloitSocketProtocol(Encoding.UTF8, XPloitSocketProtocol.EProtocolMode.Byte); using (XPloitSocket server = new XPloitSocket(proto, 77) { TimeOut = TimeSpan.Zero }) using (XPloitSocket client = new XPloitSocket(proto, "127.0.0.1:77") { TimeOut = TimeSpan.Zero }) { server.OnMessage += s_OnMessage; server.Start(); client.OnMessage += client_OnMessage; client.Start(); IXPloitSocketMsg ret = server.Clients[0].SendAndWait(new XPloitMsgLogin() { Domain = "2500bytes".PadLeft(2000, ' '), User = "******", Password = "******" }); if (ret != null) { isover = true; } while (!isover) Thread.Sleep(1); } }
static void noserver_thread(object o) { XPloitSocket cs = (XPloitSocket)o; XPloitSocketClient c = cs._Client; bool checkTimeOut = cs._TimeOut != TimeSpan.Zero; try { while (!cs._IsStopping && c.IsConnected) { //lectura sincrona en este hilo if (!cs.Read(c) && checkTimeOut && c.HasTimeOut) { if (DateTime.Now - c.LastRead > cs._TimeOut && !cs.RaiseOnTimeOut(c)) { c.Disconnect(EDissconnectReason.TimeOut); break; } } Thread.Sleep(0); } } catch { } cs.Remove(c, c.DisconnectReason); cs.Stop(true); }
void s_OnMessage2(XPloitSocket sender, XPloitSocketClient cl, IXPloitSocketMsg msg) { // Server receive msg XPloitMsgString msgS = (XPloitMsgString)msg; //XPloitTelnetProtocol.Send(cl, XPloitTelnetProtocol.GetColorMessage()); //XPloitTelnetProtocol.Send(cl, new byte[] { 255, 247 }); XPloitTelnetProtocol.Send(cl, "Received: " + msgS.Data + Environment.NewLine); //isover = true; }
public void TestTelnetProtocol() { using (XPloitSocket server = new XPloitSocket(new XPloitTelnetProtocol(Encoding.UTF8), 23) { TimeOut = TimeSpan.Zero }) { server.OnConnect += s_OnConnect2; server.OnMessage += s_OnMessage2; server.Start(); while (!isover) Thread.Sleep(1); } }
public override bool Start() { Stop(); // Crypt password AESHelper crypt = null; if (_Config.CryptKey != null && !string.IsNullOrEmpty(_Config.CryptKey.RawPassword)) crypt = new AESHelper(_Config.CryptKey.RawPassword, "Made with love ;)", 20000, "**#Int#Vector#**", AESHelper.EKeyLength.Length_256); _Socket = new XPloitSocket(new XPloitSocketProtocol(_Codec, crypt, XPloitSocketProtocol.EProtocolMode.UInt16), _Config.Address, _Config.Port, _IsServer) { IPFilter = _IPFilter, TimeOut = TimeSpan.Zero }; _Socket.OnConnect += _Socket_OnConnect; _Socket.OnDisconnect += _Socket_OnDisconnect; _Socket.OnMessage += _Socket_OnMessage; return _Socket.Start(); }
static void server_thread(object o) { XPloitSocket cs = (XPloitSocket)o; DateTime time = DateTime.Now; bool check_time_out = cs._TimeOut != TimeSpan.Zero; AsyncCallback callme = new AsyncCallback(cs.socket_acept); cs._Server.BeginAccept(callme, cs); while (!cs._IsStopping) { //lock (cs._Clients) ya hace el lock el añadido //{ for (int x = cs._Clients.Length - 1; x >= 0; x--) { XPloitSocketClient c = cs._Clients[x]; //lectura sincrona en este hilo if (!cs.Read(c) && check_time_out && c.HasTimeOut) { if (DateTime.Now - c.LastRead > cs._TimeOut && !cs.RaiseOnTimeOut(c)) { cs.Remove(c, EDissconnectReason.TimeOut); continue; } } if (!c.IsConnected) { cs.Remove(c, c.DisconnectReason); } //} } Thread.Sleep(0); } }
void s_OnConnect2(XPloitSocket sender, XPloitSocketClient cl) { //XPloitTelnetProtocol.Send(cl, new byte[] { 255, 247 }); //XPloitTelnetProtocol.Send(cl, XPloitTelnetProtocol.GetColorMessage()); XPloitTelnetProtocol.Send(cl, "server to client" + Environment.NewLine); }
void s_OnMessage(XPloitSocket sender, XPloitSocketClient cl, IXPloitSocketMsg msg) { // Server receive msg isover = true; }
void client_OnMessage(XPloitSocket sender, XPloitSocketClient cl, IXPloitSocketMsg msg) { // Client receive message cl.Send(new XPloitMsgLogin() { Domain = "?", User = "******", Password = "******", InResponseTo = msg.Id }); }
public override bool Stop() { if (_Socket != null) { _Socket.Dispose(); _Socket = null; } return true; }
void _Socket_OnMessage(XPloitSocket sender, XPloitSocketClient client, IXPloitSocketMsg msg) { }
void _Socket_OnDisconnect(XPloitSocket sender, XPloitSocketClient client, EDissconnectReason e) { }
void _Socket_OnConnect(XPloitSocket sender, XPloitSocketClient client) { }