コード例 #1
0
 private static void Disconnected()
 {
     Thread.Sleep(1000);
     FConsole.WriteLine("Socket disconnected!");
     Client               = new ClientSocket(ushort.MaxValue);
     Client.OnConnected  += Connected;
     Client.OnDisconnect += Disconnected;
     Client.ConnectAsync(ServerHostname, ServerPort);
 }
コード例 #2
0
        public void ConnectAsync(string user, string pass)
        {
            User = user;
            Pass = pass;
            ReceiveQueue.OnPacket += OnPacket;

            Socket = new ClientSocket(this);
            Socket.OnDisconnect += Disconnected;
            Socket.OnConnected  += Connected;
            Socket.ConnectAsync(Core.SERVER_IP, Core.SERVER_PORT);
        }
コード例 #3
0
        public static async Task Main()
        {
            FConsole.WriteLine("Host: ");
            ServerHostname       = Console.ReadLine().Trim();
            Client.OnConnected  += Connected;
            Client.OnPacket     += PacketRouter.Handle;
            Client.OnDisconnect += Disconnected;
            Client.ConnectAsync(ServerHostname, ServerPort);

            while (true)
            {
                var msg = Console.ReadLine();

                switch (msg)
                {
                case "login":
                    Client.Send(MsgLogin.Create("asd", "asdasd", true, MsgLoginType.Login));
                    break;

                case "ping":
                    var array  = new byte[MsgBench.MAX_ARRAY_LENGTH];
                    var random = new Random();
                    for (var i = 0; i < array.Length; i++)
                    {
                        array[i] = (byte)random.Next(0, 255);
                    }
                    Stopwatch.Start();
                    for (var i = 0; i < 1000; i++)
                    {
                        var msgBench = MsgBench.Create(array, false);
                        Client.Send(msgBench);
                    }
                    break;

                case "send":
                    var user = (User)Client.StateObject;
                    FConsole.WriteLine("Requesting Token...");
                    user.Send(MsgToken.Create("transcoder", 0, true));
                    while (!user.Tokens.ContainsKey(0))
                    {
                        Thread.Sleep(1);
                    }
                    FConsole.WriteLine("Uploading... using " + user.Tokens[0]);
                    Stopwatch.Start();
                    await user.SendFile(@"/home/alumni/transcoder", 0);

                    Stopwatch.Stop();
                    FConsole.WriteLine($"Done. {Stopwatch.Elapsed.TotalSeconds.ToString("##.##")}");
                    break;
                }
            }
        }