【发布时间】:2020-10-31 13:42:50
【问题描述】:
我只是想通过套接字从我的服务器向我的客户端发送一个整数。
public static DataOutputStream toClient = null;
public static int clients = 0;
public static void main(String args[]) throws IOException {
ServerSocket serverSocket = new ServerSocket(1039);
System.out.println("Server is running..");
while (true) {
Socket connsock = null;
try {
// accepting client socket
connsock = serverSocket.accept();
toClient = new DataOutputStream(connsock.getOutputStream());
System.out.println("A new client is connected : " + connsock);
clients = clients + 1;
toClient.writeUTF(clients); //here, I get the incompatible types; int cannot be converted to string
}
}
}
}
我明白了:
不兼容的类型; int 不能转成字符串
与toClient.writeUTF(clients);在线。
怎么了?
【问题讨论】: