我正在尝试构建这个服务器客户端程序,使它们能够相互发送,而不受双工通信类型的限制。我尝试过使用接口(interface) Runnable,但我对它的工作原理有点困惑,我应该创建 2 个 Runnable 接口(interface),一个接收数据,一个发送数据,这样如果我在主类中运行它,只需将它们添加为 Thread 即可。 这会让我的聊天程序同时运行吗?
class ServerSend implements Runnable{
//CONSTRUCTOR
public Server{
//is the constructor really necessary or should I just code in my run() void?
}
public void () run{
//
//Where the code should be placed??(Confused)..
}
最佳答案
为了实现在网络中工作的服务器-客户端接口(interface),我将使用套接字并连接到 ServerSockets。然后,您将拥有一个运行客户端的线程和一个运行接受新客户端的服务器的线程。
关于java - 线程和java/服务器-客户端程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29913114/