服务器套接字和多个客户端 运行 可以在一台主机上吗?
Can Server Socket and multiple clients run on a single host?
我们可以 运行 在一台机器上安装多个客户端和 1 个服务器吗?
假设我有一个服务器 class(多连接线程)和一个客户端 class。我想同时 运行 至少 2 个客户端,但他们有单独的聊天 window(服务器到客户端但不是群聊)。可能吗?
我有这个代码
public void server(){
ss = new ServerSocket(port);
chatprocess cp = new chatprocess(socket);// accept connection inside and input/output as well
}
public client(){
socket = new socket("localhost",port);
clientprocess(); //i/o inside
}
是的。
为此,您必须为每个客户端创建一个线程。 SO里有很多例子。
我们可以 运行 在一台机器上安装多个客户端和 1 个服务器吗? 假设我有一个服务器 class(多连接线程)和一个客户端 class。我想同时 运行 至少 2 个客户端,但他们有单独的聊天 window(服务器到客户端但不是群聊)。可能吗? 我有这个代码
public void server(){
ss = new ServerSocket(port);
chatprocess cp = new chatprocess(socket);// accept connection inside and input/output as well
}
public client(){
socket = new socket("localhost",port);
clientprocess(); //i/o inside
}
是的。
为此,您必须为每个客户端创建一个线程。 SO里有很多例子。