private static void LogicRun() { g_client = new Dictionary <IntPtr, Session>(); for (int i = startId; i < endId; i++) { TcpClientEx client = new TcpClientEx("127.0.0.1", 13006, 5, OnSocket); Session s = new Session(client); if (client.Connect(true)) { s.SocketState = SocketState.CHECKING; s.ID = i; s.SendFirstSelfSalt(); //s.LoginGame("soul" + i.ToString(), "0000", "魔域"); g_client[client.ConnectionId] = s; } } while (true) { Dictionary <IntPtr, Session> dic = new Dictionary <IntPtr, Session>(g_client); foreach (Session client in dic.Values) { client.Run(); } System.Threading.Thread.Sleep(4); } }
public bool UserLogonRequest() { #region TcpClientEx tcpclient = new TcpClientEx( ServerInfor._Ip.ToString(), Convert.ToInt16(ServerInfor._Port)); SendUserValidCheck senduservalidcheck = new SendUserValidCheck() { _UserInfor = _User }; byte[] command = senduservalidcheck.GetProtocolCommand(); tcpclient.Connect(); tcpclient.SendToEndDevice(command); tcpclient.Receive(); RecvUserCheckResult usercheckresult = new RecvUserCheckResult(); tcpclient.Dispatcher(usercheckresult); tcpclient.Close(); if (usercheckresult._Result._Success) { string message = usercheckresult._Result._Message; int splitindex = message.IndexOf("-"); _User.uid = message.Substring(0, splitindex); _User.userfullName = message.Substring(splitindex + 1, message.Length - splitindex - 1); } return(usercheckresult._Result._Success); #endregion }
/// <summary> /// /// </summary> private void requestUserList() { #region TcpClientEx tcpclient = new TcpClientEx( ServerInfor._Ip.ToString(), Convert.ToInt16(ServerInfor._Port)); SendRequstFriendShip sendrequestfriendship = new SendRequstFriendShip() { _UserInfor = Logon._User }; byte[] command = sendrequestfriendship.GetProtocolCommand(); ExtConsole.WriteByteArray(command); tcpclient.Connect(); tcpclient.SendToEndDevice(command); tcpclient.ReceiveFile(); //RecvUserCheckResult usercheckresult = new RecvUserCheckResult(); //tcpclient.Dispatcher(usercheckresult); //Console.WriteLine(usercheckresult._Result._Message); tcpclient.Close(); #endregion }
//public event EventHandler<ReceiveEventArgs> OnReceive = null; public static TcpClientEx ConnectServer() { #region TcpClientEx tcpclient = new TcpClientEx( ServerInfor._Ip.ToString(), Convert.ToInt16(ServerInfor._Port)); tcpclient.Connect(); return(tcpclient); #endregion }
private void _server_ClientStatusChanged(object sender, ClientStatusChangedEventArgs args) { if (!IsRunning) { return; } long proxyClientID = args.ClientID; if (args.Status == ClientStatus.Connected) { TcpClientEx tcpClient = new TcpClientEx(RawPacketSpliter.Default); tcpClient.Tag = proxyClientID; tcpClient.ClientStatusChanged += TcpClient_ClientStatusChanged; tcpClient.MessageReceived += TcpClient_MessageReceived; Task.Factory.StartNew(() => { bool isConnected = tcpClient.Connect(RemoteIP, (ushort)RemotePort); if (isConnected) { bool isOK = _clientDict.TryAdd(proxyClientID, tcpClient); System.Diagnostics.Debug.Assert(isOK, "add new client failed"); } else { _server.CloseClient(proxyClientID); } if (_waitConnDict.ContainsKey(proxyClientID)) { _waitConnDict[proxyClientID].Set(); } }); } else if (args.Status == ClientStatus.Closed) { if (_clientDict.TryRemove(proxyClientID, out TcpClientEx client)) { client.Close(); } } ClientCount = _server.Clients.Count; if (ClientCountChanged != null) { ClientCountChangedEventArgs countChangedArgs = new ClientCountChangedEventArgs() { NewCount = ClientCount }; ClientCountChanged(this, countChangedArgs); } }
public TcpClientEx ConnectTo(IPEndPoint connectTo) { var client = new TcpClientEx(); try { client.Connect(connectTo); } catch (SocketException) { throw new ConnectionEstablisherException(); } return(client); }
private void btnConnect_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(tbServerIP.Text) || string.IsNullOrEmpty(tbServerPort.Text)) { return; } client.Connect(tbServerIP.Text, tbServerPort.Text); Task t = new Task(GetDataAndUpdateConsolOutputBox); t.Start(); lbStatus.Content = "Connected"; btnConnect.IsEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnStartSend_Click(object sender, EventArgs e) { MethodInvoker gd = new MethodInvoker(() => { TcpClientEx tcpclient = new TcpClientEx("192.168.159.104", 1005); SendFileSyn transfilesyn = new SendFileSyn(); tcpclient.Connect(); tcpclient.SendToEndDevice(transfilesyn.GetProtocolCommand()); tcpclient.Receive(); RecvFileAck transfileack = new RecvFileAck(); transfileack.OnStartingDownload += new EventHandler(StartingDownload); tcpclient.Dispatcher(transfileack); tcpclient.Close(); }); gd.BeginInvoke(null, null); }