package four; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; /** *监听客户端发送过来的信息 * *发送服务器的信息 * * @author czx */ public class VoteThread extends Thread { private Socket toClientSocket = null;// 会话套接字 public BufferedReader in; // 网络输入流 PrintWriter out; // 网络输出流 @SuppressWarnings("unused") private int clientCounts = 0;// 在线客户机总数 public VoteThread(Socket toClientSocket, int clientCounts) { // 构造函数 this.toClientSocket = toClientSocket; this.clientCounts = clientCounts; } @Override public void run() { try { // 创建绑定到套接字toClientSocket上的网络输入流与输出流 in = new BufferedReader(new InputStreamReader(toClientSocket.getInputStream(), "UTF-8")); out = new PrintWriter(new OutputStreamWriter(toClientSocket.getOutputStream(), "UTF-8"), true); String recvStr; recvStr = in.readLine(); while (recvStr != null) { switch (recvStr) { case "Info": // 发送候选人信息 out.println(VoteServer.str1); out.println(VoteServer.str2); out.println(VoteServer.str3); out.println(VoteServer.str4); out.println(VoteServer.str5); // 发送票数信息 out.println(VoteServer.textField_7.getText()); out.println(VoteServer.textField_8.getText()); out.println(VoteServer.textField_9.getText()); out.println(VoteServer.textField_10.getText()); out.println(VoteServer.textField_11.getText()); out.flush(); case "submit": // 接收票数信息 @SuppressWarnings("unused") String str = in.readLine(); String str1 = in.readLine(); String str2 = in.readLine(); String str3 = in.readLine(); String str4 = in.readLine(); String str5 = in.readLine(); VoteServer.textField_7.setText(str1); VoteServer.textField_8.setText(str2); VoteServer.textField_9.setText(str3); VoteServer.textField_10.setText(str4); VoteServer.textField_11.setText(str5); case "refresh": // 发送票数信息 out.println(VoteServer.textField_7.getText()); out.println(VoteServer.textField_8.getText()); out.println(VoteServer.textField_9.getText()); out.println(VoteServer.textField_10.getText()); out.println(VoteServer.textField_11.getText()); default: break; } } } catch (IOException ex) { } finally { try { if (toClientSocket != null) toClientSocket.close(); // 断开连接 } catch (IOException e) { e.printStackTrace(); } } } // end run } // end class
最近下载更多
求学的熊猫 LV7
2023年12月26日
微信网友_5973767083364352 LV1
2022年5月25日
微信网友_5927360927125504 LV1
2022年4月22日
543666826 LV33
2022年3月12日
William2342 LV1
2022年2月8日
lllayc LV1
2022年1月3日
Thynpa LV1
2021年12月23日
1095402829 LV18
2021年12月15日
Derrick LV1
2021年12月15日
Undead LV2
2021年12月14日
最近浏览更多
akittyboy LV9
3月22日
wananall LV13
3月13日
laishaofe LV7
1月16日
求学的熊猫 LV7
2023年12月25日
lshlsh
2023年12月25日
暂无贡献等级
shiaomon
2023年12月14日
暂无贡献等级
嗯嗯嗯嗯嗯嗯2528
2023年11月29日
暂无贡献等级
ftc1314 LV12
2023年11月2日
2017143155 LV12
2023年6月23日
2057889678
2023年6月8日
暂无贡献等级