Here is a simple TCPServer implementation where all I wanted to do was send a string to the client on request.
import java.util.*;
import java.io.*;
import java.net.*;
class TCPServer{
public static void main(String args[]) throws Exception{
ServerSocket server = new ServerSocket(4888);
while(true){
Socket client = server.accept();
DataOutputStream out = new DataOutputStream(client.getOutputStream());
String send = "Bhushan Patil \n 11-237 \n CMPN";
out.writeBytes(send);
}
}
}
But on the clinic side only Bhushan Patil is shown not the rest of the line.
Here is the client code.
import java.util.*;
import java.io.*;
import java.net.*;
class TCPClient{
public static void main(String args[]) throws Exception{
Socket client = new Socket("localhost",4888);
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream ()));
String display = in.readLine();
System.out.println(display);
}
}
Can anyone explain why this is happening? When i do
System.out.println(send);
I get the whole line with \ n, so I assume you will not get new lines. Correct me if I am wrong. Thanx
source
share