Ejemplo n.º 1
0
        private void EndAccepting(IAsyncResult result)
        {
            var client = new Client(InternalSocket.EndAccept(result));

            client.StartReceive();
            InternalSocket.BeginAccept(EndAccepting, null);
        }
Ejemplo n.º 2
0
        public void Listen(int port)
        {
            InternalSocket.Bind(new IPEndPoint(IPAddress.Any, port));

            InternalSocket.Listen(100);

            InternalSocket.BeginAccept(AcceptCallback, this);
        }
Ejemplo n.º 3
0
        public void Listen(IPEndPoint hostEndPoint)
        {
            InternalSocket.Bind(hostEndPoint);

            InternalSocket.Listen(100);

            InternalSocket.BeginAccept(AcceptCallback, this);
        }
Ejemplo n.º 4
0
        private void AcceptCallback(IAsyncResult ar)
        {
            var socketObject = new SocketObject(InternalSocket.EndAccept(ar));

            if (SocketConnected != null)
            {
                SocketConnected(socketObject);
            }

            socketObject.BeginReceive(this);

            InternalSocket.BeginAccept(AcceptCallback, this);
        }
Ejemplo n.º 5
0
        public void Start()
        {
            try
            {
                InternalSocket.Bind(ServerEndPoint);
                InternalSocket.Listen(500);
                InternalSocket.BeginAccept(EndAccepting, null);
            }
            catch (SocketException ex)
            {
                if (ex.ErrorCode == (int)SocketError.AddressAlreadyInUse)
                {
                    throw new InvalidOperationException("The selected port is already used by another process");
                }

                throw new NotSupportedException("oops unexpected error was thrown please report this issue to the developer.");
            }
        }