예제 #1
0
        protected virtual async Task OnLogin(AsyncTcpClient client)
        {
            if (!string.IsNullOrEmpty(UserName))
            {
                RPCPacket packet = new RPCPacket();
                packet.Url       = LOGIN_TAG;
                packet.Data      = new object[] { UserName, PassWord };
                packet.NeedReply = true;
                var response = await SendWait(packet, client);

                if (response.Status != (short)StatusCode.SUCCESS)
                {
                    client.DisConnect();
                    throw new XRPCException((string)response.Data[0]);
                }
            }
            if (Connected != null)
            {
                await Connected(client);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            AsyncTcpClient client = SocketFactory.CreateClient <AsyncTcpClient>("127.0.0.1", 9090);

            //AsyncTcpClient client = SocketFactory.CreateSslClient<AsyncTcpClient>("127.0.0.1", 9090, "localhost");
            client.ClientError = (c, e) =>
            {
                Write(string.Format("client error {0} {1}\r\n", e.Error, e.Message));
            };


            client.DataReceive = (o, e) =>
            {
                string line = e.Stream.ToPipeStream().ReadLine();
                Cmd    cmd  = ChatParse.Parse(line);
                Console.WriteLine(cmd.Text);
            };
            while (true)
            {
                Write("login enter you name:");
                string line = Console.ReadLine();
                string cmd  = ChatParse.CreateCommand(CmdType.LOGIN, line);
                client.Connect();
                client.Stream.ToPipeStream().WriteLine(cmd);
                client.Stream.Flush();
                while (true)
                {
                    line = Console.ReadLine();
                    if (line == "quit")
                    {
                        client.DisConnect();
                        break;
                    }
                    cmd = ChatParse.CreateCommand(CmdType.SPEAK, line);
                    client.Stream.ToPipeStream().WriteLine(cmd);
                    client.Stream.Flush();
                }
            }
        }
예제 #3
0
 public void Dispose()
 {
     OnWSConnected = false;
     mNetClient.DisConnect();
     mNetClient = null;
 }
예제 #4
0
 public void Close()
 {
     client.DisConnect();
 }