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); } }
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(); } } }
public void Dispose() { OnWSConnected = false; mNetClient.DisConnect(); mNetClient = null; }
public void Close() { client.DisConnect(); }