Exemplo n.º 1
0
        public void ExecuteWithCommunication()
        {
            if (SelfSubmitter.AmIRootProcess())
            {
                AsynchronousServer server       = new AsynchronousServer(C.DEFAULT_PORT);
                AutoResetEvent     receivedDone = new AutoResetEvent(false);
                server.NewMessageReceivedEvent += (objectRecv, sock) => {
                    if (objectRecv is ISystemMessage hello)
                    {
                        hello.Dispatch(sock);
                    }

                    if (objectRecv is string s)
                    {
                        Console.Out.WriteLine(s);
                        receivedDone.Set();
                    }
                };
                server.Start();
                //receivedDone.WaitOne();
                SubmitNewCopyOfMyself();
                while (true)
                {
                    Thread.Sleep(1000);
                    Console.Out.WriteLine("Received msgs so far: {0}", AsynchronousCommunicationUtils.reception);
                }
            }
            else if (SelfSubmitter.GetMyNestLevel() == 1)
            {
                ClientExample();
            }
        }
Exemplo n.º 2
0
            private void connectionRead(AsynchronousServer.ClientConnection clientConnection)
            {
                ClientConnection cc = (ClientConnection)clientConnection;

                try
                {
                    if (cc.progressiveMessage.ToString().StartsWith(GET))
                    {
                        if (cc.progressiveMessage.ToString().EndsWith(HEADER_END))
                        {
                            HTTPRequest request = new HTTPRequest();
                            request.parse(cc.progressiveMessage.ToString());
                            processRequest(cc, request);
                        }

                        if (cc.progressiveMessage.Length > configuration.maxRequestLength)
                        {
                            throw new RequestEntityTooLargeResponsePage();
                        }
                    }
                    else
                    {
                        throw new BadRequestResponsePage();
                    }
                }
                catch (HTTPResponse r)
                {
                    cc.Send(r);
                }
                catch (Exception e)
                {
                    cc.Send(new ExceptionResponsePage(e.Message + " " + e.StackTrace));
                }
            }
Exemplo n.º 3
0
 private void connection(AsynchronousServer.ClientConnection cc)
 {
     //Register events before commencing the connection.
     cc.OnConnectionNotify += new AsynchronousServer.Server.ConnectionNotify(connectionOut);
     cc.OnConnectionRead += new AsynchronousServer.Server.ConnectionRead(connectionRead);
     cc.startConnection();
 }
Exemplo n.º 4
0
        public MainForm()
        {
            InitializeComponent();

            try
            {
                this.pictureBox1.Image = new Bitmap(@"\n2f.bmp");
                this.BTON.Image = new Bitmap(@"\btON.bmp");
            }
            catch
            {

            }

            lblBluetooth.Text = "Bluetooth is ON - Searching...";
            BluetoothRadio br = BluetoothRadio.PrimaryRadio;
            br.Mode = RadioMode.Discoverable;

            if (br == null)
            {
                MessageBox.Show("Bluetooth radio is being used. Restart device for quick fix");
                Application.Exit();
            }

            if (br.LocalAddress.ToString() == AsynchronousClient.BTAddress.ToString())
            {
                // BOB is the server so he needs to have the server listener running
                OtherName = "Alice";
                //MessageBox.Show("I am BOB");

                // set alices address
                AsynchronousClient.BTAddress = new BluetoothAddress(new byte[] { 175, 223, 244, 227, 23, 0, 0, 0 });

                AsynchronousClient AClient = new AsynchronousClient(this);

                ThreadClient = new Thread(new ThreadStart(AClient.StartSending));
                ThreadClient.Start();

                // start the Asynchronous server
                AsynchronousServer AServer = new AsynchronousServer(this);

            }
            else
            {
                OtherName = "Bob";
                //MessageBox.Show("I am ALICE");

                AsynchronousClient AClient = new AsynchronousClient(this);

                ThreadClient = new Thread(new ThreadStart(AClient.StartSending));
                ThreadClient.Start();

                // start the Asynchronous server
                AsynchronousServer AServer = new AsynchronousServer(this);
                
            }
        }
Exemplo n.º 5
0
        public ServerViewModel()
        {
            StartServerCommand = new DelegateCommand(StartServer);
            StopServerCommand  = new DelegateCommand(StopServer);

            Server = new AsynchronousServer();

            LogList           = new ObservableCollection <LogItemViewModel>();
            NetworkInterfaces = new ObservableCollection <IPAddress>(AsynchronousServer.AvailableNetworkInterfaces());

            App.LogMessage += App_LogMessage;
        }
Exemplo n.º 6
0
        public bool process(AsynchronousServer.ClientConnection cc, HTTPRequest request)
        {
            if (request.path.StartsWith("/telemachus/datalink"))
            {
                String args = request.path.Remove(0, request.path.IndexOf('?') + 1);
                String[] argsSplit = args.Split('&');

                foreach (String arg in argsSplit)
                {

                }
            }

            return false;
        }
Exemplo n.º 7
0
        public bool process(AsynchronousServer.ClientConnection cc, HTTPRequest request)
        {
            if (request.path.StartsWith("/telemachus"))
            {
                try
                {
                    cc.Send(new OKPage(System.IO.File.ReadAllText(request.path.TrimStart(new char[]{'/'}))).ToString());
                }
                catch
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            AsynchronousServer.StartListening();
            //AsynchronousClient tt = new AsynchronousClient();
            //AsynchronousClient2 tt = new AsynchronousClient2();
            //tt.StartClient();
            //AsyncConnectTest<string> a1 = new AsyncConnectTest<string>("0822", "127.0.0.1", 999, 10, 1000, 1000);
            //a1.Start();

            //for (int i = 0; i < 120; i++)
            //{
            //    //string s2 = "Qoo" + i.ToString();
            //    //a1.Send<string>(s2);
            //    //Thread.Yield();
            //    //a1.SendSynchronous(s2);
            //    Thread t = new Thread((object o) =>
            //    {
            //        string s = o as string;
            //        a1.Send<string>(s);
            //        //a1.SendSynchronous(s);
            //    });
            //    t.Start("Qoo" + i);
            //    //t.Join();
            //}
            //do
            //{
            //    string sendStr = Console.ReadLine();
            //    a1.Send<string>(sendStr);
            //}
            //while (consoleStr != "exit");
            //Thread.Sleep(15000);
            Console.ReadKey();
            //a1.Stop();
            //Console.WriteLine("Start Async Connect...");



            //Console.ReadKey();
        }
Exemplo n.º 9
0
 public HTTPRequestEventArgs(AsynchronousServer.ClientConnection clientConnection, HTTPRequest request)
 {
     this.clientConnection = clientConnection;
     this.request = request;
     cancel = false;
 }
Exemplo n.º 10
0
 public bool process(AsynchronousServer.ClientConnection cc, HTTPRequest request)
 {
     cc.Send(new PageNotFoundResponsePage().ToString());
     return true;
 }
Exemplo n.º 11
0
 public void processRequest(AsynchronousServer.ClientConnection cc, HTTPRequest request)
 {
     foreach (IHTTPRequestResponsibility responsibility in requestChainOfResponsibility)
     {
         if (responsibility.process(cc, request))
         {
             break;
         }
     }
 }
Exemplo n.º 12
0
 public ClientConnection(Socket socket, AsynchronousServer.Server server, 
     ServerConfiguration configuration)
     : base(socket, server)
 {
     this.configuration = configuration;
 }
 public ClientConnection(Socket socket, AsynchronousServer.Server server,
     ServerConfiguration configuration, Dictionary<string, IWebSocketService> webSocketServices,
     HTTPRequest request)
     : this(socket, server, configuration, webSocketServices)
 {
     this.request = request;
 }
            public ClientConnection(Socket socket, AsynchronousServer.Server server,
                ServerConfiguration configuration, Dictionary<string, IWebSocketService> webSocketServices)
                : base(socket, server)
            {
                this.configuration = configuration;
                this.server = server;
                this.webSocketServices = webSocketServices;

                data = new List<byte>();
                frame = new WebSocketFrame();
                request = new HTTPRequest();

                ConnectionRead += StatefulWebSocketHandShake;
            }
Exemplo n.º 15
0
 public bool process(AsynchronousServer.ClientConnection cc, HTTPRequest request)
 {
     cc.Send(new IOLessDataLinkNotFound().ToString());
     return true;
 }
Exemplo n.º 16
0
 public ConnectionEventArgs(AsynchronousServer.ClientConnection clientConnection)
 {
     this.clientConnection = clientConnection;
 }
Exemplo n.º 17
0
 public ConnectionNotifyEventArgs(String message,
         AsynchronousServer.ClientConnection clientConnection)
     : base(clientConnection)
 {
     this.message = message;
 }
Exemplo n.º 18
0
 private void connectionOut(AsynchronousServer.ClientConnection cc, String message)
 {
     if (OnServerNotify != null)
     {
         OnServerNotify(message);
     }
 }