public void Connect(EndPoint remoteEndPoint) { TcpClientSession session = new TcpClientSession(remoteEndPoint, bufferPoolSize, bufferSize, loger); session.OnReceived += OnReceived; session.OnConnected += OnConnected; session.OnDisConnect += OnDisConnect; session.Connect(); }
public void Login(string UserId, string PassWord) { Client.Connect(); if (!m_OpenedEvent.WaitOne(5000)) { throw new Exception("连接超时"); } byte[] userIddata = Encoding.UTF8.GetBytes(UserId); byte[] pwddata = Encoding.UTF8.GetBytes(PassWord); SendData(UserOP.DoLogin, userIddata, pwddata); }
public void ChatConn(string toUserAddr, int toUserPort) { ToUserAddr = toUserAddr; ToUserPort = toUserPort; EndPoint endpoint = new IPEndPoint(IPAddress.Parse(toUserAddr), toUserPort - 1); MyAsyncTcpSession chatsession = new MyAsyncTcpSession(endpoint, 1024 * 10); chatsession.Error += chatsession_Error; chatsession.DataReceived += chatsession_DataReceived; chatsession.Connected += chatsession_Connected; chatsession.Closed += chatsession_Closed; Client = chatsession; Client.Connect(); if (!m_OpenedEvent.WaitOne(5000)) { throw new Exception("连接超时"); } var currentSessionIdData = Encoding.UTF8.GetBytes(CurrentUser.SessionId); this.SendData(UserOP.DoNewChat, currentSessionIdData); }
//--------------------------------------------------------------------- public void Connect(string ip_or_host, int port) { mIpOrHost = ip_or_host; mPort = port; IPAddress ip_address = null; bool is_host = !IPAddress.TryParse(mIpOrHost, out ip_address); IPHostEntry host_info = null; if (is_host) { host_info = Dns.GetHostEntry(mIpOrHost); } else { host_info = Dns.GetHostEntry(ip_address); } IPAddress[] ary_IP = host_info.AddressList; if (is_host) { mSession = new TcpClientSession(mIpOrHost, mPort); } else { EndPoint server_address = new IPEndPoint(IPAddress.Parse(mIpOrHost), mPort); mSession = new TcpClientSession(server_address); } mSession.OnDataReceived += _onReceive; mSession.OnConnected += _onConnected; mSession.OnClosed += _onClosed; mSession.OnError += _onError; mSession.Connect(ary_IP, is_host); }