- Joined
- Mar 3, 2005
- Location
- Jacksonville, FL
I just wanted to see if anyone is familiar with programming Sockets using Java for Client/Server environment. I'm just trying to write a simple program that on the Client side lets user choose form couple of different options then sends that request over a Socket to Server program that processes the request and returns it back to Client. I'm using PrintWriter for output to Client from Server program but it just won't work if I put it inside a conditional statement as so:
The line that I'm talking about is the print.println. I've checked around the web and no one seems to know why this is so wanted to try my luck here
Anyways if anyone knows, that would be of great help
Code:
ServerSocket serverSock = null;
Socket standSock = null;
try
{
serverSock = new ServerSocket(7003);
standSock = serverSock.accept();
InputStreamReader input = new InputStreamReader(standSock.getInputStream());
BufferedReader read = new BufferedReader(input);
PrintWriter print = new PrintWriter(standSock.getOutputStream(), false);
String dateTime = (Calendar.getInstance()).getTime().toString();
if (read.readLine().equals("1"))
{
System.out.println("Option 1");
print.println("You're connected to the Server at: " + dateTime);
}
System.out.println("Closing Server Connection");
read.close();
input.close();
print.close();
standSock.close();
}
The line that I'm talking about is the print.println. I've checked around the web and no one seems to know why this is so wanted to try my luck here
Anyways if anyone knows, that would be of great help