gpt4 book ai didi

java - 这段代码有什么问题?

转载 作者:行者123 更新时间:2023-12-01 07:42:28 25 4
gpt4 key购买 nike

我今天刚刚开始尝试 java(有 javascript 和 PHP 经验),但在编译此代码时遇到了问题。

我在 Mac 上使用 NewBeans IDE 6.8。

它只是说“一个或多个项目编译时出现错误。”

当我尝试添加自定义函数时,问题就开始了。

这是代码(忽略所有注释):

import java.io.*;
import java.net.*;

public class simpleServer
{
public static void main(String args[])
{
}

public void clientLoop()
{
// Message terminator
char EOF = (char)0x00;

try
{
// create a serverSocket connection on port 9999
ServerSocket s = new ServerSocket(4041);

System.out.println("Server started. Listening for connections...");
// wait for incoming connections
Socket incoming = s.accept();

BufferedReader data_in = new BufferedReader(
new InputStreamReader(incoming.getInputStream()));
PrintWriter data_out = new PrintWriter(incoming.getOutputStream());

data_out.println("Connected to Shipz Server." + EOF);
data_out.flush();

boolean quit = false;


while (!quit)
{
String msg = data_in.readLine();

if (msg == null) quit = true;

if (!msg.trim().equals("EXIT"))
{
if(msg.trim().equals("hShipzClient"))
{
System.out.println("Client Connected");
}

if(msg.trim().equals("c")){
System.out.println("Player collision");
data_out.println("You crashed!");
}
data_out.flush();
}
else
{
quit = true;
}
}
}
catch (Exception e)
{
System.out.println("Connection lost");
}
}

谢谢

最佳答案

我认为您在程序末尾缺少一个结束大括号“}”。

关于java - 这段代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2292094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com