Socket not receiving data stream
I am new to programming sockets with Java and I have a few questions. My client connects to the server, however when I try to send just a simple string and display it on the server it doesn't work. I have seen several tutorials that all used different input/output stream classes, what is the suggested class to send string data? Below is my code: (Note: all exception handling was taken out for purposes of this post)
Server:
ServerSocket server =new ServerSocket(port,100);
System.out.println("Waiting for connection\n");
Socket connection = server.accept();
System.out.println("Connection received from: " + connection.getInetAddress().getHostName());
DataInputStream input =new DataInputStream(connection.getInputStream());
while(true)
{
String line = input.readLine();
System.out.println(line);
}
Client:
Socket client =new Socket(hostName,portNum);
DataOutputStream output =new DataOutputStream(client.getOutputStream());
output.writeBytes("Test");
Message was edited by:
jwarzech

