public ClientV2() { _quit = false; _listener = new EventBasedNetListener(); _client = new NetManager(_listener); _client.DisconnectTimeout = 60000; step = ConnectionStep.Disconnected; }
//使用BackgroundWorker private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { ConnectionStep step = (ConnectionStep)e.Argument; switch (step) { case ConnectionStep.ConnectDatabase: FirstStep(); break; default: break; } }
private void btnDBConnNext_Click(object sender, EventArgs e) { steps = ConnectionStep.ConnectDatabase; backgroundWorker1.RunWorkerAsync(steps); this.btnDBConnNext.Enabled = false; this.progressBar1.Value = 0; int i = 0; while (backgroundWorker1.IsBusy) { progressBar1.Increment(1); //if (progressBar1.Value > 98) // progressBar1.Value = 0; Application.DoEvents(); } }
public void ProcessClientHello(IPEndPoint ip) { if (ClientConnectionStep == ConnectionStep.None) { ClientConnectionStep = ConnectionStep.Hello; } IP = ip; //using (var cc = new ConsoleCopy(Settings.LogFile)) //{ Console.WriteLine("Client Hello! IP: {0}", ip); //} //TODO Server.instance.SendServerHello(IP, ID, 3567); ClientConnectionStep = ConnectionStep.Playing; }
public void connect(string host, int port) { if (step != ConnectionStep.Disconnected) { return; //One connection at a time } Console.WriteLine("Client connecting..."); step++; _client.Start(); _client.Connect(host, port, "FrozenPizza" /* text key or NetDataWriter */); //Disconnect handler _listener.PeerDisconnectedEvent += (peer, disconnectInfo) => { step = ConnectionStep.Disconnected; Menu.OpenModal("Disconnected from server:" + disconnectInfo.Reason.ToString(), "Error"); Engine.setState(GameState.Menu); GameMain.Reset(); }; _listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod) => { ClientHandlerV2.Parse(fromPeer, dataReader, deliveryMethod); }; run(); }