/// <summary> /// Event handler for when a new client (master) has connected. /// </summary> private static void ClientConnected(MeisterSocket socket, MeisterSocket client_socket) { Logger.Info("Ah! A fresh slave! I like!"); //Lol re-using event handlers.. client_socket.PacketReceived += PacketReceived; client_socket.Closed += Closed; }
static void Main(string[] args) { MeisterSocket socket = new MeisterSocket(); socket.Connected += Connected; socket.Closed += Closed; socket.Connect("127.0.0.1", 1337); Exit.WaitOne(); int i = 0; }
/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name="args">The command-line arguments.</param> private static void Main(string[] args) { //Initialize the socket and the manual reset event Program.Exit = new ManualResetEvent(false); Program.Server = new MeisterSocket(); //Setup the event handlers for the socket Program.Server.Connected += Connected; Program.Server.Closed += Closed; Program.Server.ClientConnected += ClientConnected; Program.Server.PacketReceived += PacketReceived; //Start listening for incoming connections and block //until the exit event is triggered.. Program.Server.Listen(1337); Program.Exit.WaitOne(); }
static void Connected(MeisterSocket socket) { Logger.Info("I have connected to the allmighty Master!"); socket.Send(new TestPacket(12)); }
static void Closed(MeisterSocket socket) { Exit.Set(); }
/// <summary> /// Callback for when we have an incoming connection. /// </summary> protected void OnAccept(IAsyncResult result) { MeisterSocket client_socket = new MeisterSocket(this.BaseSocket.EndAccept(result)); //Fake invoke the 'Connected' event on the client socket client_socket.OnConnected(null); if(this.ClientConnected != null) this.ClientConnected.BeginInvoke(this, client_socket, OnClientConnctedInvoked, null); }
/// <summary> /// Event handler for when a packet is received. /// </summary> private static void PacketReceived(MeisterSocket socket, IMeisterPacket packet) { if (packet.GetIdentifier() != 0) return; TestPacket pack = (TestPacket)packet; Logger.Info("Received a packet from one of my minions... " + pack.Neger.ToString()); }
/// <summary> /// Event handler for when the server has started listening for incoming connections. /// </summary> private static void Connected(MeisterSocket socket) { Logger.Info("Started listening!"); }
/// <summary> /// Event handler for when the connection attempt failed, or remote end point /// closed the connection. /// </summary> private static void Closed(MeisterSocket socket) { Logger.Info("Client disconnected..."); }