コード例 #1
0
ファイル: Form_SendTo.cs プロジェクト: cfrpg/Publish
 private void button_OK_Click(object sender, EventArgs e)
 {
     List<IPAddress> targets = new List<IPAddress>();
     for (int i = 0, sz = listBox_Confirm.Items.Count; i < sz; i++)
     {
         string ucl = listBox_Confirm.Items[i].ToString();
         targets.Add(players.__table[facebook[ucl]].clientIP);
     }
     Parallel.ForEach( targets, (item, state, i) =>
     {
         TcpClientP home = new TcpClientP();
         home.Connect(new IPEndPoint(item, Port.TCP_BOOK_INFORMATION_PORT));
         home.Write(data);
         home.Close();
     });
     MessageBox.Show("所有数据发送完毕!", "提示", MessageBoxButtons.OK);
     this.Close();
 }
コード例 #2
0
ファイル: Form_Main.cs プロジェクト: cfrpg/Publish
 private void tSMI_Sendto_Click(object sender, EventArgs e)
 {
     BookEvaluaionList data = new BookEvaluaionList();
     for (int i = 0, sz = listView_Books.SelectedItems.Count; i < sz; i++)
     {
         string id = listView_Books.SelectedItems[i].SubItems[0].Text;
         BookEvaluaion tmp = new BookEvaluaion();
         BookEval.tryFind(int.Parse(id), out tmp);
         data.Add(tmp);
     }
     byte[] raw;
     ToBytes<BookEvaluaionList>.GetBytes(ref data, out raw);
     TcpClientP home = new TcpClientP();
     home.Connect(new IPEndPoint(serverIP, Port.TCP_BOOK_EVALUATION_PORT));
     home.Write(raw);
     home.Close();
     MessageBox.Show("发送成功", "提示", MessageBoxButtons.OK);
 }
コード例 #3
0
ファイル: Form_Main.cs プロジェクト: cfrpg/Publish
 private void OnClientLogin(ref IPAddress where, ref string[] result, out string answer)
 {
     User client; answer = VerMessage.DEFAULT_RESPONSE;
     int idx = users.Find(result[1], out client);
     // 用户不存在
     if (idx == -1)
     {
         answer = VerMessage.LOGIN_FAILED_NO_SUCH_USER;
         return;
     }
     // 检查密码
     if (!client.testPassword(result[2]))
     {
         answer = VerMessage.LOGIN_FAILED_WRONG_PW;
         return;
     }
     // 发送用户个人资料
     tcpClientUserFile = new TcpClientP();
     tcpClientUserFile.Connect(new IPEndPoint(where, Port.TCP_USER_FILE_PORT));
     string data = client.toUserFile();
     tcpClientUserFile.Write(data);
     tcpClientUserFile.Close();
     // 加入连接列表
     Client login = new Client(where, client);
     onlineUsers.AddClient(login);
     Invoke(new AddUserIntoToListView_dele(AddUserIntoView), new object[] {client.account, client.name });
     // 反馈消息
     answer = VerMessage.LOGIN_SUCCESS;
 }