Esempio n. 1
0
        public static void MainListener(Life life, int port)
        {
            TcpListener listener;

            listener = new TcpListener(port);
            listener.Start();

            while(true)
            {
                Socket connection = listener.AcceptSocket();

                NetworkStream socketstream = new NetworkStream( connection );

                BinaryReader reader = new BinaryReader(socketstream);

                string serviceName = reader.ReadString();

            /*
                TODO: Pesquisar como instanciar um objeto a partir de objeto Type;
                        Isso eliminará os "cases";

                NetworkBridge servico = new System.Type.GetType(serviceName))();

                servico.respondTo("");

            */				string response = "";
                string serviceData = reader.ReadString();

                switch (serviceName)
                {
                    case "NameService":
                        {
                            NameService service = new NameService(life);
                            response = service.respondTo(serviceData);
                            break;
                        }

                    default:{break;}
                }

                new BinaryWriter(socketstream).Write(response);

            }
        }
Esempio n. 2
0
        public void Connect()
        {
            try
            {
                String name ;

                NameService ns = new NameService(life);
                name = ns.CallService("oi",contact.IP);

                contact.Status = "Online";
                contact.Name = name;

            }
            catch(Exception ex)
            {
                contact.Status = "Invalid Address" + ex.Message;
                return;
            }
        }