Beispiel #1
0
        static void Main(string[] args)
        {
            Setup();
            _client.Send(new ClientInfo(Environment.OSVersion.ToString(), Environment.UserName, Environment.MachineName, new Version("0.4.0")));

            Console.WriteLine("Info set. You can now send messages.");

            var connected = true;

            _client.OnDisconnect += (s, err) => connected = false;

            //_client.Send(new DesktopScreenshot(ScreenCapture.GetDesktopScreenshot()));

            while (connected)
            {
                HandleCommands(connected, ConsoleExtentions.GetNonEmptyString(""));
            }

            ConsoleExtentions.ErrorAndClose("Lost connection to server");
        }
Beispiel #2
0
        public override Guid Call(params object[] args)
        {
            var id = Guid.NewGuid();

            _client.Send(new RemoteCallRequest
            {
                Name   = _name,
                CallId = id,
                Args   = args
            });
            return(id);
        }
Beispiel #3
0
        public override Guid Call(object[] args)
        {
            var id = Guid.NewGuid();

            client.Send(new RemoteCallRequest()
            {
                Name   = Name,
                CallID = id,
                Args   = args
            });
            return(id);
        }
Beispiel #4
0
        private static void Client()
        {
            //When sending custom objects, you must create a new packer and specify them.
            var packer = new Packager(new Type[] {
                typeof(SetName),
                typeof(ChatMessage)
            });

            //Using ipv4 and the packer that has the custom types.
            var client = new SyncIOClient(TransportProtocal.IPv4, packer);

            //The diffrent types of handlers: (all optional)

            //The type handler.
            //This handler handles a specific object type.
            client.SetHandler <ChatMessage>((SyncIOClient sender, ChatMessage messagePacket) => {
                //All ChatMessage packages will be passed to this callback
                Console.WriteLine(messagePacket.Message);
            });

            //This handler handles any IPacket that does not have a handler.
            client.SetHandler((SyncIOClient sender, IPacket p) => {
                //Any packets without a set handler will be passed here
            });

            //This handler handles anything that is not a SINGLE IPacket object
            client.SetHandler((SyncIOClient sender, object[] data) => {
                //Any object array sent will be passed here, even if the array contains
                //A packet with a handler (e.g. ChatMessage)
            });



            if (!client.Connect("127.0.0.1", new Random().Next(9996, 10000)))//Connect to any of the open ports.
            {
                ConsoleExtentions.ErrorAndClose("Failed to connect to server.");
            }

            //Connecting and handshake are not the same.
            //Connecting = Establishing a connection with a socket
            //Handskake  = Establishing a connection with a SyncIOServer and getting an ID.
            Console.WriteLine("Connected on port {0}. Waiting for handshake.", client.EndPoint.Port);

            bool success = client.WaitForHandshake();

            /*
             * The asynchronous way to get handshake would be subscribing
             * to the client.OnHandshake event.
             */

            if (!success)
            {
                ConsoleExtentions.ErrorAndClose("Handshake failed.");
            }

            Console.WriteLine("Handshake success. Got ID: {0}", client.ID);

            var name = ConsoleExtentions.GetNonEmptyString("Enter a name: ");

            client.Send(new SetName(name));

            Console.WriteLine("Name set. You can now send messages.");

            bool connected = true;

            client.OnDisconnect += (s, err) => {
                connected = false;
            };

            var GetTime    = client.GetRemoteFunction <string>("GetTime");
            var toggletime = client.GetRemoteFunction <string>("toggletime");

            while (connected)
            {
                var msg = ConsoleExtentions.GetNonEmptyString("");

                if (msg == "time")
                {
                    //Call a function that requires authentication checking.
                    GetTime.CallWait();                                       //If call failed, return will be the default value for the type
                    if (GetTime.LastStatus == FunctionResponceStatus.Success) //No issues
                    {
                        Console.WriteLine(GetTime.LastValue);                 //Write last returned value to console
                    }
                    else
                    {
                        Console.WriteLine("Call failed. reason: {0}. Try the \"toggletime\" command", GetTime.LastStatus);
                    }
                }
                else if (msg == "toggletime")
                {
                    Console.WriteLine(toggletime.CallWait()); //If call fails, nothing (null) will be printed because it is strings default value.
                }
                else
                {
                    if (connected)
                    {
                        client.Send(new ChatMessage(msg));
                    }
                }
            }
            ConsoleExtentions.ErrorAndClose("Lost connection to server");
        }