Ejemplo n.º 1
0
        public override void Listen()
        {
            byte[]     sa    = isAbstract ? UnixNativeTransport.GetSockAddrAbstract(unixPath) : UnixNativeTransport.GetSockAddr(unixPath);
            UnixSocket usock = new UnixSocket();

            usock.Bind(sa);
            usock.Listen(50);

            while (true)
            {
                Console.WriteLine("Waiting for client on " + (isAbstract ? "abstract " : String.Empty) + "path " + unixPath);
                UnixSocket csock = usock.Accept();
                Console.WriteLine("Client connected");

                ServerConnection conn;
                if (!AcceptClient(csock, out conn))
                {
                    Console.WriteLine("Client rejected");
                    csock.Close();
                    continue;
                }

                //GLib.Idle.Add (delegate {

                if (NewConnection != null)
                {
                    NewConnection(conn);
                }

                //BusG.Init (conn);

                /*
                 * conn.Iterate ();
                 * Console.WriteLine ("done iter");
                 * BusG.Init (conn);
                 * Console.WriteLine ("done init");
                 */

                //GLib.Idle.Add (delegate { BusG.Init (conn); return false; });
        #if USE_GLIB
                BusG.Init(conn);
        #else
                new Thread(new ThreadStart(delegate { while (conn.IsConnected)
                                                      {
                                                          conn.Iterate();
                                                      }
                                           })).Start();
        #endif
                Console.WriteLine("done init");


                //return false;
                //});
            }
        }
Ejemplo n.º 2
0
        public override void Listen()
        {
            TcpListener server = new TcpListener(IPAddress.Any, (int)port);

            server.Server.Blocking = true;

            server.Start();

            while (true)
            {
                //Console.WriteLine ("Waiting for client on TCP port " + port);
                TcpClient client = server.AcceptTcpClient();

                /*
                 * client.NoDelay = true;
                 * client.ReceiveBufferSize = (int)Protocol.MaxMessageLength;
                 * client.SendBufferSize = (int)Protocol.MaxMessageLength;
                 */
                //Console.WriteLine ("Client connected");

                ServerConnection conn;
                if (!AcceptClient(client, out conn))
                {
                    Console.WriteLine("Client rejected");
                    client.Close();
                    continue;
                }

                //client.Client.Blocking = false;


                //GLib.Idle.Add (delegate {

                if (NewConnection != null)
                {
                    NewConnection(conn);
                }

                //BusG.Init (conn);

                /*
                 * conn.Iterate ();
                 * Console.WriteLine ("done iter");
                 * BusG.Init (conn);
                 * Console.WriteLine ("done init");
                 */

                //GLib.Idle.Add (delegate { BusG.Init (conn); return false; });
        #if USE_GLIB
                BusG.Init(conn);
        #else
                new Thread(new ThreadStart(delegate { while (conn.IsConnected)
                                                      {
                                                          conn.Iterate();
                                                      }
                                           })).Start();
        #endif
                //Console.WriteLine ("done init");

                //return false;
                //});
            }
        }