//页面初始布置 public Window1() { InitializeComponent(); this.user = ClientSocket.User; labelUserName.Content = user.NickName; rectangleBottom.Fill = new SolidColorBrush(user.Color); ButtonBack.Background = new SolidColorBrush(user.Color); TextSysInfo.Background = new SolidColorBrush(user.LightColor); ButtonBack.PreviewMouseUp += ButtonBack_PreviewMouseUp; ButtonBack.MouseEnter += ButtonBack_MouseEnter; ButtonBack.MouseLeave += ButtonBack_MouseLeave; labelUserName.MouseUp += labelUserName_MouseUp; }
//连接服务器 public static int ConnectServer(string name,string password="") { user = new User(name, password); IPAddress ip = IPAddress.Parse(host); IPEndPoint ipe = new IPEndPoint(ip, port); soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { soc.Connect(ipe); } catch (SocketException e) { System.Windows.MessageBox.Show("服务器连接错误!请检查服务器地址:" + host + ":" + port.ToString()); return 1; } sendUserInfo(); startListening(); MessagesKeeper.Get(0, 3); return 0; }