Beispiel #1
0
        public static void Pending()
        {
            if (Server == null || BreakTcpLoop)
            {
                return;
            }
            try
            {
                /*Thread tmpThread = new Thread(() =>*/
                {
                    Client = Server.AcceptTcpClient();
                    TCPState.IsConnected = true;
                    log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:TCP Client connected. Setting TCPState.IsConnected = true.");

                    //TCP Message
                    TcpMessageThread = new Thread(WaitForMessage);
                    TcpMessageThread.Start();
                }
                //);
                //tmpThread.Start();
            }
            catch (Exception ex)
            {
                log.Error($"[{Settings.GetLine(new StackTrace(true))}]:Error pending TCP client: " + ex);
            }
        }
        public FlareTcpClient AcceptClient()
        {
            EnsureRunning();
            var client = Server.AcceptTcpClient();

            return(WrapIntoClient(client));
        }
Beispiel #3
0
 private void AcceptBackground()
 {
     while (true)
     {
         var client = Server.AcceptTcpClient();
         Task.Factory.StartNew(() => HandleClient(client));
     }
     // ReSharper disable once FunctionNeverReturns
 }
Beispiel #4
0
 public void AcceptBackground()
 {
     while (true)
     {
         var client = Server.AcceptTcpClient();
         Console.WriteLine("-> Request from " + client.Client.RemoteEndPoint);
         Task.Factory.StartNew(() => HandleClient(client));
     }
 }
Beispiel #5
0
 public void AcceptBackground()
 {
     while (true)
     {
         var handler = Server.AcceptTcpClient();
         Console.WriteLine("Client " + handler.Client.RemoteEndPoint + " connected.");
         RunBackground(handler);
     }
     // ReSharper disable once FunctionNeverReturns
 }
Beispiel #6
0
        public void ListenForConnections()
        {
            //start server
            Server.Start();

            //listen for incoming connection and start a thread that handels the connection (functioon processconnection)
            while (true)
            {
                IMyTcpClient client = new MyTcpClient(Server.AcceptTcpClient());
                Thread       threadToProcessClient = new Thread(delegate() { ProcessConnection(client); });
                threadToProcessClient.Start();
            }
        }
Beispiel #7
0
 private void Listen()
 {
     Server.Start();
     while (Listening)
     {
         TcpClient           client     = Server.AcceptTcpClient();
         IConnectionProtocol protocol   = new TCPConnectionProtocol(client);
         ConnectionManager   manager    = new ConnectionManager(protocol);
         Connection          connection = manager.GetConnection();
         connection.SubscribeToAll();
         Connections.Add(connection);
     }
     Server.Stop();
 }
Beispiel #8
0
 public void Start()
 {
     Server.Start();
     Started?.Invoke(this, EventArgs.Empty);
     while (!Stop)
     {
         ToStop?.Invoke(this, EventArgs.Empty);
         if (Stop)
         {
             Close();
             break;
         }
         var client = new ClientSocket(Server.AcceptTcpClient());
         OnClientAccepting?.Invoke(this, client);
         AcceptedClientsAmount++;
     }
 }
Beispiel #9
0
        private static void Listen()
        {
            Task.Run(() =>
            {
                var data = new List <byte>();
                byte[] buffer;

                while (true)
                {
                    foreach (var client in Clients)
                    {
                        data.Clear();
                        if (client.Connected)
                        {
                            var stream = client.GetStream();

                            while (client.Available > 0)
                            {
                                buffer = new byte[Math.Min(Conduit.BufferSize, client.Available)];

                                stream.Read(buffer, 0, buffer.Length);

                                data.AddRange(buffer);
                            }

                            if (data.Count > 0)
                            {
                                DataReceived(null, new PacketReceivedEventArgs {
                                    Packet = ConduitPacket.Deserialize(data.ToArray())
                                });
                            }
                        }
                    }

                    if (!Server.Pending())
                    {
                        continue;
                    }

                    Clients.Add(Server.AcceptTcpClient());

                    ClientConnected(null, EventArgs.Empty);
                }
            });
        }
Beispiel #10
0
        public void Run(string[] args)
        {
            Server.Start();

            var bytes = new byte[256];

            StoogeWorld.StoogeWorld.Load();

            Console.WriteLine($"Server listening at {_localAddress}:{_port}");

            while (true)
            {
                var client = Server.AcceptTcpClient();

                Console.WriteLine("Connection accepted...");

                var stream = client.GetStream();
                var p      = new Player(stream);

                int i;

                //Main Mud Loop
                while ((i = p.Read(bytes, 0, bytes.Length)) != 0)
                {
                    // Translate data bytes to a ASCII string.
                    var data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                    Console.WriteLine("Received: {0}", data);

                    // Process the data sent by the client.
                    data = data.ToUpper();

                    var msg = System.Text.Encoding.ASCII.GetBytes(data);

                    // Send back a response.
                    stream.Write(msg, 0, msg.Length);
                    Console.WriteLine("Sent: {0}", data);
                }

                //Handle Ticks
                _lastPulse = World.Pulse(_lastPulse);

                //Handle World Resets
            }
        }
Beispiel #11
0
        /// <summary>
        /// This will send a request for sensor initialization to the SensorNetworkServer, where the
        /// SensorNetworkServer will then respond with sensor initialization.
        /// </summary>
        /// <returns>The sensor initialization byte array.</returns>
        private byte[] RequestAndAcquireSensorInitialization()
        {
            // Start the server that will expect the Sensor Configuration
            Server.Start();

            // Wait for the SensorNetworkClient to send the initialization
            TcpClient localClient;

            byte[] receivedInit = new byte[SensorNetworkConstants.SensorNetworkSensorCount];

            // Once this line is passed, we have connected and received the initialization
            localClient = Server.AcceptTcpClient();
            logger.Info($"{Utilities.GetTimeStamp()}: Simulation Sensor Network received Sensor Initialization");
            ServerStream = localClient.GetStream();
            ServerStream.Read(receivedInit, 0, receivedInit.Length);

            // We will now dispose of the Server/Stream components because that is the only time we are using it
            ServerStream.Close();
            ServerStream.Dispose();
            Server.Stop();

            return(receivedInit);
        }
Beispiel #12
0
        /// <summary>
        /// Starts the proxy by waiting for connections
        /// </summary>
        public override void DoWork()
        {
            try
            {
                Logger.AddToInfoView("Starting the proxy on {0}", Configuration.ProxyServerEndPoint);
                Server.Start();

                for (;;)
                {
                    if (this.CheckForCancel())
                    {
                        return;
                    }

                    InvalidServerCertificate = this.GenerateCert("wpad_audit");
                    TcpClient client = Server.AcceptTcpClient();
                    Task.Factory.StartNew(() => this.HandleClient(client), BaseWorker.StopToken.Token);
                }
            }
            catch (Exception ex)
            {
                Logger.AddToErrorView("Proxy.DoWork", ex);
            }
        }
Beispiel #13
0
 public JfpClient AcceptJfpClient()
 {
     return(new JfpClient(Decorator(Server.AcceptTcpClient().GetStream())));
 }
Beispiel #14
0
 public Client()
 {
     TClient = Server.AcceptTcpClient();
     TStream = TClient.GetStream();
 }