I'm writing a simple server and client in java for an assignment and I can't even seem to get the server to receive anything from the client.
I'm using a PrintWriter to send data from the client and a Scanner to receive it on the server.
In all blatant honesty... I don't really know what I'm doing... at all. So it's incredibly likely that I've overlooked something stupid. I went ahead and copied both files in full below for review. Thanks for any help!
Client Code:
Server:
I'm using a PrintWriter to send data from the client and a Scanner to receive it on the server.
In all blatant honesty... I don't really know what I'm doing... at all. So it's incredibly likely that I've overlooked something stupid. I went ahead and copied both files in full below for review. Thanks for any help!
Client Code:
Code:
import java.io.*;
import java.util.*;
import java.net.*;
public class myClient {
protected static Socket sock;
public static void main(String args[]) {
try {
sock = new Socket("127.0.0.1",55555);
DataInputStream response = new DataInputStream(sock.getInputStream());
PrintWriter request = new PrintWriter(sock.getOutputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String txt = "";
while(!txt.equals("EXIT")) {
System.out.print("prompt:");
txt = in.readLine();
request.print(txt);
request.flush();
}
response.close();
request.close();
in.close();
sock.close();
} catch(IOException e) {
System.out.println(e.toString());
}
}
}
Server:
Code:
import java.io.*;
import java.util.*;
import java.net.*;
public class myServer {
protected static final int PORT_NUMBER = 55555;
public static void main( String args[]) {
try {
ServerSocket servsock = new ServerSocket(PORT_NUMBER);
String instr;
while(true) {
Socket sock = servsock.accept();
Scanner in = new Scanner(sock.getInputStream());
PrintWriter out = new PrintWriter(sock.getOutputStream());
System.out.println(in.next());
in.close();
out.close();
sock.close();
}
} catch(Exception e) {
System.out.println(e.toString());
}
}
}