This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Client Server Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Client Server Communication" Watch "Client Server Communication" New topic

Client Server Communication

Vikram Deshmukh

Joined: Apr 22, 2000
Posts: 29
Dear Friends ,
I want to implement simple client - server communication .
My server is already running , then i'm separately running my Client.
At console i'm going to make an input . It will be read as a readLine.
The same will be displayed at Server side.
If instead of Client , if i use , Telnet it works appropriately .
Can anybody please tell me whats wrong ?
from ,
Vikram .

///////////// Server Side Code ////////////////////////
public class Server
public static void main(String[] args)throws IOException
ServerSocket servsock = new ServerSocket(4444);
System.out.println("Server is running");
Socket soc;
soc = servsock.accept();
System.out.println("Until here is OK ! - 0");
InputStreamReader isr = new InputStreamReader(soc.getInputStream());
BufferedReader br = new BufferedReader(isr);
String str = br.readLine();
System.out.println("Until here is OK ! - 1");
System.out.println("String received at Server : "+str);
//////////////// Client Side Code ////////////////////////
public class Client
public static void main(String[] args)throws IOException
BufferedReader in = new BufferedReader(new InputStreamReader(;
String input = in.readLine();
Socket sock = new Socket(InetAddress.getLocalHost(),4444);
OutputStreamWriter osw = new OutputStreamWriter(sock.getOutputStream());
System.out.println("String for Server is : "+osw);
Harish Kashyap
Ranch Hand

Joined: Jun 14, 2000
Posts: 118
at the end of the line send '\n' character to the server.
server is reading with readLine() method which will not accept until u send '\n' character to it.
Don't get me started about those stupid light bulbs.
subject: Client Server Communication
Similar Threads
Dynamic IP address and socket programming.
simple socket program not working right
still not solved
How to send a message back from Server to Client?