예제 #1
0
        public TestEnvironment(int clientCount, Action <NetServer> execSetup)
        {
            ServerHost = new NetServer(true);
            ServerHost.ServerChangeMaxPlayers(clientCount + 1);
            execSetup(ServerHost);

            IPEndPoint hostEndpoint = new IPEndPoint(IPAddress.Parse("1.1.1.1"), 4444);

            SocketHost = ServerHost.OpenVirtual(new VirtualSocket[clientCount],
                                                new IPEndPoint[clientCount],
                                                hostEndpoint);

            Clients       = new NetServer[clientCount];
            SocketClients = new VirtualSocket[clientCount];
            for (int i = 0; i < clientCount; i++)
            {
                IPEndPoint clientEndpoint = new IPEndPoint(IPAddress.Parse("3.3.3." + i), 4444);
                Clients[i] = new NetServer(false, hostEndpoint);
                execSetup(Clients[i]);
                SocketClients[i] = Clients[i].OpenVirtual(new VirtualSocket[] { SocketHost },
                                                          new IPEndPoint[] { hostEndpoint },
                                                          clientEndpoint);

                SocketHost.Targets[i]   = SocketClients[i];
                SocketHost.Addresses[i] = clientEndpoint;
            }
        }
예제 #2
0
        /// <summary>
        /// Start server.
        /// </summary>
        public void Start()
        {
            _server.Start();
            Console.WriteLine("Started");

            while (true)
            {
                try
                {
                    VirtualSocket lastAcceptedSocket = _server.AcceptSocket();

                    if (lastAcceptedSocket != null)
                    {
                        ThreadPool.QueueUserWorkItem(delegate(object o)
                        {
                            CreateSession(lastAcceptedSocket);
                        });
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
            }
        }
예제 #3
0
        private void CreateSession(VirtualSocket socket)
        {
            try
            {
                Console.WriteLine("New connection");

                var             options = new ProtocolOptions();
                ProtocolSession session = new ProtocolSession(socket, options);
                session.OnStreamOpened += session_OnStreamOpened;
                session.OnError        += session_OnError;
                session.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #4
0
파일: NNTP.cs 프로젝트: spotnet/fusenet
        public bool Connect()
        {
            try
            {
                if (iConnection.Cancelled)
                {
                    return(false);
                }

                if (SocketStatus == NNTPStatus.Multiline)
                {
                    SocketStatus = NNTPStatus.Singleline;
                }

                if (SocketStatus == NNTPStatus.Singleline)
                {
                    Ready(0, "");
                    return(true);
                }

                SocketStatus = NNTPStatus.Connecting;

                if (iSocket == null)
                {
                    if (!iServer.SSL)
                    {
                        iSocket = new Socket();
                    }
                    else
                    {
                        iSocket = new SSLSocket();
                    }

                    iSocket.Received     += new EventHandler <WorkArgs>(iReceived);
                    iSocket.Connected    += new EventHandler <WorkArgs>(iConnected);
                    iSocket.Disconnected += new EventHandler <WorkArgs>(iDisconnected);
                }

                return(iSocket.Connect(iServer));
            }
            catch (Exception ex)
            {
                Disconnect(996, ex.Message, false);
                return(false);
            }
        }
예제 #5
0
파일: NNTP.cs 프로젝트: spotnet/fusenet
        private void iDisconnected(object sender, WorkArgs e)
        {
            iSocket      = null;
            SocketStatus = NNTPStatus.Closed;

            //Debug.WriteLine("iDisconnected: " + e.Message);

            try
            {
                if ((e != null) && (Failed != null))
                {
                    Failed(e.Code, e.Message, iServer.Log, this);
                }
            }
            catch { }

            if (Closed != null)
            {
                Closed(this);
            }
        }