我用教程创建了一个非常基本的 Java 服务器。目标是让 gamemaker studio 2 客户端连接并与该服务器通信。我对 GML 有更多的经验。所以服务器正在启动(java)并且客户端(GMS2)连接成功。我有一些检查以确保。如果客户端向服务器发送消息,服务器永远不会收到它,直到客户端断开连接。
这是java代码:
import java.net.*;
import java.io.*;
public class GameServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(6666);
Socket client = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream(), true);
out.println("hello gamemaker studio: "); //the clients receive this message
while(true) {
System.out.println("in while loop");//the server console prints this message
String string = in.readLine();//keeps stuck on this
//after client disconnect, all messages the client has sent are displayed in the console
System.out.println("reading string:" + string);
if (string == null) { break; }
out.println("we have received this answer: " + string );
System.out.println("stopped");
}
}
}
出于某种原因,我不知道它一直停留在这条线上: String string = in.readLine(); 我制作了一个 java 客户端来测试它。java客户端一切正常。所以游戏制作者代码一定有问题