private void buttonRegister_Click(object sender, RoutedEventArgs e) { if (this.textBoxUsername.Text.Length <= 0) { MessageBox.Show("請輸入帳號"); return; } if (this.textBoxPassword.Password.Length <= 0) { MessageBox.Show("請輸入密碼"); return; } if (this.client == null) { this.client = ChatSocket.connect(ChatSetting.serverIp); try { client.newListener(receiveFromServer); } catch (Exception err) { Console.WriteLine(err.ToString()); } } if (this.req_packet == null) { this.req_packet = new Packet(); } this.req_packet.MakePacketRequestUserRegister(this.textBoxUsername.Text, this.textBoxPassword.Password); this.sendToServer(null, this.req_packet); }
public void run() //執行Socket { IPEndPoint ipep = new IPEndPoint(IPAddress.Any, ChatSetting.port); Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); newsock.Bind(ipep); newsock.Listen(10); while (true) { Socket socket = newsock.Accept(); Console.WriteLine("接受一個新連線!"); ChatSocket client = new ChatSocket(socket); try { client.number = _clientList.Count(); _clientList.Add(client); client.newListener(processMsgComeIn); } catch { } // clientList.Remove(client); } // newsock.Close(); }
public LogInWindow(string serverIp) { InitializeComponent(); gridHome.Visibility = Visibility.Collapsed; stackPanelLogIn.Visibility = Visibility.Visible; this.req_packet = new Packet(); this.client = ChatSocket.connect(serverIp); try { client.newListener(receiveFromServer); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private bool logIn(string username) { myName = username; if (this.client == null) { this.client = ChatSocket.connect(ChatSetting.serverIp); try { client.newListener(receiveFromServer); } catch (Exception e) { Console.WriteLine(e.ToString()); } } bool connectSuccess; //client = ChatSocket.connect(ChatSetting.serverIp); if (client == null) { connectSuccess = false; } else { connectSuccess = true; } if (connectSuccess) { LoginIn = true; Packet packet = new Packet(); packet.makePacketReportName(username, this.textBoxPassword.Password); sendToServer(null, packet); } return(connectSuccess); }