//連線 private void btnConnection_Click(object sender, EventArgs e) { if (userName_textBox.Text == "") { MessageBox.Show("需要輸入暱稱才能連線"); } else { userName = userName_textBox.Text; ConnectionServer connectionserver = new ConnectionServer("13.75.120.16", "5555"); //server IP and port //ConnectionServer connectionserver = new ConnectionServer("127.0.0.1", "5555"); //server IP and port socketClient = connectionserver.Connection2Server(); //連線至server localName = socketClient.LocalEndPoint.ToString(); this.btnConnection.Enabled = false; Thread thrReceived = new Thread(ReceiveMsg); //建立線程來監聽訊息 thrReceived.IsBackground = true; thrReceived.SetApartmentState(ApartmentState.STA); thrReceived.Start(); receiveFlag = true; //開始監聽 this.groupBox3.Enabled = true; this.txtReceived.Text = ""; this.txtReceived.AppendTxt("等待配對中..."); this.txtMessage.Enabled = false; this.userName_textBox.Enabled = false; this.btnShake.Enabled = false; this.btnSendMsg.Enabled = false; this.btnSendFile.Enabled = false; } }
//連線 private void btnConnection_Click(object sender, EventArgs e) { ConnectionServer connectionserver = new ConnectionServer("13.75.120.16", "5555"); //server IP and port //ConnectionServer connectionserver = new ConnectionServer("127.0.0.1", "5555"); //server IP and port socketClient = connectionserver.Connection2Server(); //連線至server this.lblUid.Text = localName = socketClient.LocalEndPoint.ToString(); this.btnConnection.Enabled = false; Thread thrReceived = new Thread(ReceiveMsg); //建立線程來監聽訊息 thrReceived.IsBackground = true; thrReceived.SetApartmentState(ApartmentState.STA); thrReceived.Start(); Debug.Print("1"); this.groupBox3.Enabled = true; this.groupBox4.Enabled = true; this.lstFriends.Enabled = true; }