public msgConnectionRequest ( String IP, String Port, String Name, String CPU ) : String | ||
IP | String | |
Port | String | |
Name | String | |
CPU | String | |
return | String |
//************************************* public bool Join_Swarm(string DstIP, string DstPort,string SrcIP, string SrcPort,string Username) { Thread t1 = null; Thread t2 = null; try { t1 = new Thread(new ThreadStart(mSocket.StartListening)); t1.Start(); t1.IsBackground = true; string cpu = "1"; mSocket.SetIP(SrcIP); mSocket.SetPort(SrcPort); mSocket.SetName(Username); mSocket.SetCPU(cpu); MessageGenerator msg = new MessageGenerator(); string mMsg = msg.msgConnectionRequest (mSocket.GetIP(), mSocket.GetPort(), mSocket.GetName(), mSocket.GetCPU()); AsynchronousClient client = new AsynchronousClient(); client.SetSingleMsg(DstIP, DstPort, mMsg); t2 = new Thread(new ThreadStart(client.SendSingleClient)); t2.Start(); t2.IsBackground = true; return true; } catch (Exception ex) { Debug.WriteLine(ex.Message); return false; } }
private void Connection_Request(object sender, EventArgs e) { MessageGenerator msg = new MessageGenerator(); string DstIp = textBox1.Text; string DstPort = textBox2.Text; string mMsg = msg.msgConnectionRequest (mSocket.GetIP(), mSocket.GetPort(), mSocket.GetName(), mSocket.GetCPU()); AsynchronousClient client = new AsynchronousClient(); client.SetSingleMsg(DstIp, DstPort,mMsg); Thread t = null; t = new Thread(new ThreadStart(client.SendSingleClient)); t.Start(); t.IsBackground = true; this.button1.Enabled = false; this.button2.Enabled = false; this.button3.Enabled = true; }
//************************************* public bool Join_Swarm(string DstIP, string DstPort, string SrcIP, string SrcPort, string Username) { Thread t1 = null; Thread t2 = null; try { string cpu = "1"; mSocket.SetIP(SrcIP); mSocket.SetPort(SrcPort); mSocket.SetName(Username); mSocket.SetCPU(cpu); listenerThread = new Thread(new ThreadStart(mSocket.StartListening)); listenerThread.IsBackground = true; listenerThread.Start(); t1 = new Thread(new ThreadStart(mSocket.StarHeartBeat)); t1.IsBackground = true; t1.Start(); MessageGenerator msg = new MessageGenerator(); string mMsg = msg.msgConnectionRequest (mSocket.GetIP(), mSocket.GetPort(), mSocket.GetName(), mSocket.GetCPU()); AsynchronousClient client = new AsynchronousClient(); client.ErrorExcep += new AsynchronousClient.EventHandlerExcep(Error_Changed); client.SetSingleMsg(DstIP, DstPort, mMsg); // t2 = new Thread(new ThreadStart(client.SendSingleClient)); client.SendSingleClient(); // t2.Start(); // t2.IsBackground = true; Thread.Sleep(2000); if (mSocket.GetIPtoPeer().Count > 0) return true; else return false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Failed to join swarm."); return false; } }