I read through some of those.
I have my server code here:
import java.io.*;
import java.net.*;
class login {
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );
public static void main(String[] args) throws IOException, ServerSocketException, SocketException {
ServerSocket server = new ServerSocket(2011, 3);
Socket incoming = server.accept();
System.out.println("Socket Opened");
BufferedReader in = new BufferedReader
(new InputStreamReader(incoming.getInputStream()));
PrintWriter out = new PrintWriter
(incoming.getOutputStream(), true /* autoFlush */);
boolean done = false;
while (!done) {
String line = in.readLine();
String next = null;
String[] temp;
System.out.println(line);
if (line.trim().equals("login")) {
next = "login";
out.println("login");
}
if (line.trim().equals("BYE")) done = true;
if (next == "login") {
temp = line.trim().split(":");
out.println("Welcome " + temp[0]);
}
incoming.close();
}
}
}
I don't know what I am doing wrong, but it seems to crash right after it prints their message on screen.
I think this is because it is unable to write back to the socket.
Is there a function I should be using other than out.println?
Here is the output from my this script.
Notice I messaged the script a. It also gives the same problem when I message real commands such as login and BYE.
C:\Program Files\Java\jdk1.6.0_01\bin>java login
Socket Opened
a
Exception in thread "main" java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at login.main(login.java:21)
Thanks
Eric