Implements the connection logic for the socket server. After accepting a connection, all data read from the client is sent back to the client. The read and echo back to the client pattern is continued until the client disconnects.
Ejemplo n.º 1
0
 public void Dispose()
 {
     if (sockengine != null)
     {
         //It's important remove handlers
         ManageSocketEngineEvents(false);
         //sockengine.Dispose(); MS in his example never implement the dispose, bad habit!!.
         sockengine = null;
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int numConnections = 1;
            int receiveSize = 2048;
            IPEndPoint localEndPoint;
            int port = 11000;

            try
            {

                string addressFamily = "ipv6";

                if (numConnections <= 0)
                {
                    throw new ArgumentException("The number of connections specified must be greater than 0");
                }
                if (receiveSize <= 0)
                {
                    throw new ArgumentException("The receive size specified must be greater than 0");
                }
                if (port <= 0)
                {
                    throw new ArgumentException("The listenPort specified must be greater than 0");
                }

                // This sample supports two address family types: ipv4 and ipv6
                if (addressFamily.Equals("ipv4"))
                {
                    localEndPoint = new IPEndPoint(IPAddress.Any, port);
                }
                else if (addressFamily.Equals("ipv6"))
                {
                    localEndPoint = new IPEndPoint(IPAddress.IPv6Any, port);
                }
                else
                {
                    throw new ArgumentException("Invalid address family specified");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Usage: AsyncSocketServer.exe <#connections> <receiveSizeInBytes> <address family: ipv4 | ipv6> <Local Port Number>");
                return;
            }

            Console.WriteLine("Press any key to start the server ...");
            Console.ReadKey();

            // Start the server listening for incoming connection requests
            Server server = new Server(numConnections, receiveSize);
            server.Init();
            server.Start(localEndPoint);
            Console.Read();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            int numConnections;
            int receiveSize;
            IPEndPoint localEndPoint;
            int port;

            // parse command line parameters
            //format: #connections, receive size per connection, address family, port num
            if (args.Length < 4)
            {
                Console.WriteLine("Usage: AsyncSocketServer.exe <#connections> <receiveSizeInBytes> <address family: ipv4 | ipv6> <Local Port Number>");
                return;
            }

            try
            {
                numConnections = int.Parse(args[0]);
                receiveSize = int.Parse(args[1]);
                string addressFamily = args[2].ToLower();
                port = int.Parse(args[3]);

                if (numConnections <= 0)
                {
                    throw new ArgumentException("The number of connections specified must be greater than 0");
                }
                if (receiveSize <= 0)
                {
                    throw new ArgumentException("The receive size specified must be greater than 0");
                }
                if (port <= 0)
                {
                    throw new ArgumentException("The port specified must be greater than 0");
                }

                // This sample supports two address family types: ipv4 and ipv6
                if (addressFamily.Equals("ipv4"))
                {
                    localEndPoint = new IPEndPoint(IPAddress.Any, port);
                }
                else if (addressFamily.Equals("ipv6"))
                {
                    localEndPoint = new IPEndPoint(IPAddress.IPv6Any, port);
                }
                else
                {
                    throw new ArgumentException("Invalid address family specified");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Usage: AsyncSocketServer.exe <#connections> <receiveSizeInBytes> <address family: ipv4 | ipv6> <Local Port Number>");
                return;
            }

            Console.WriteLine("Press any key to start the server ...");
            Console.ReadKey();

            // Start the server listening for incoming connection requests
            Server server = new Server(numConnections, receiveSize);
            server.Init();
            server.Start(localEndPoint);
        }
Ejemplo n.º 4
0
 public SocketComunicator()
 {
     this.sockengine = new Server(10, 2048);
     ManageSocketEngineEvents(true);
     sockengine.Init();
 }