我用教程创建了一个非常基础的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 = in.readLine(); 我制作了一个Java客户端来对其进行测试。 Java客户端一切正常。 因此,游戏者代码一定有问题