PDA

Click to See Complete Forum and Search --> : illegal start of type?{resolved}


Dillinger4
Nov 19th, 2003, 12:31 AM
Any ideas why the compiler keeps pissing about an illegal start of type at while(true){? I compile this class under the command line system compiler and using Eclipse and i keep getting the same results. :mad:

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

class Server{
private ServerSocket ser;
private Socket soc;
private OutputStreamWriter out;
private int port;

public Server(int port){
this.port = port;
try{
ser = new ServerSocket(port);
}catch(IOException e){
System.out.println("Port" + ser.getLocalPort() + "is occupied");
}
}

while(true){
try{
soc = ser.accept();
out = new OutputStreamWriter(soc.getOutputStream());
out.write("port open \r\n");
soc.close();
}catch(IOException e){
/*
transitory exception\client broke the connection early
*/
}
}
}

CornedBee
Nov 19th, 2003, 05:29 AM
Presentable case of formatting error :)

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

class Server{
private ServerSocket ser;
private Socket soc;
private OutputStreamWriter out;
private int port;

public Server(int port){
this.port = port;
try{
ser = new ServerSocket(port);
}catch(IOException e){
System.out.println("Port" + ser.getLocalPort() + "is occupied");
}
}

while(true){
try{
soc = ser.accept();
out = new OutputStreamWriter(soc.getOutputStream());
out.write("port open \r\n");
soc.close();
}catch(IOException e){
/*
transitory exception\client broke the connection early
*/
}
}
}

Dillinger4
Nov 19th, 2003, 10:29 AM
So what is the problem? :lol: All the brackets seem to be in the correct location. :confused:

CornedBee
Nov 19th, 2003, 02:01 PM
Get glasses and look closely! The while loop is outside the function!

Dillinger4
Nov 19th, 2003, 03:54 PM
eeek. :D I must be going crazy. Thanks. :)