I just started experimenting with java today (have experience with javascript and PHP) and am having trouble compiling this code.
I am using NewBeans IDE 6.8 on Mac.
It just says “One or more projects were compiled with errors.”
The problem began when I tried adding a custom function in.
Here’s the code (ignore all the comments):
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");
}
}
Thanks
i think you are missing an ending curly-brace “}” at the very end of your program.