Meaningless Drivel is fun!*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Client Server Communication" Watch "Client Server Communication" New topic
Author

Client Server Communication

Vikram Deshmukh
Greenhorn

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;
for(;
{
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);
// THIS PROGRAM WORKING FINE WITH TELNET uptill this
}
}
}
//////////////// Client Side Code ////////////////////////
public class Client
{
public static void main(String[] args)throws IOException
{
//BUFFERED READER TO INPUT STREAM
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = in.readLine();
Socket sock = new Socket(InetAddress.getLocalHost(),4444);
OutputStreamWriter osw = new OutputStreamWriter(sock.getOutputStream());
osw.write(input,0,input.length());
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Client Server Communication
 
Similar Threads
simple socket program not working right
still not solved
sockets
How to send a message back from Server to Client?
Dynamic IP address and socket programming.