Im just trying to send an integer from my server to my client via sockets.
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
}
}
}
}
I get:
incompatible types; int cannot be converted to string
on the line with toClient.writeUTF(clients);.
what is wrong?