wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes still not solved Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "still not solved" Watch "still not solved" New topic
Author

still not solved

anuj khanna
Greenhorn

Joined: Jan 11, 2001
Posts: 20

//server side
import java.io.*;
import java.net.*;
class clientsoc1{
public static void main(String args[]) throws Exception
{
InetAddress i=InetAddress.getLocalHost();
String str=new String();
String strt=new String();
Socket soc=new Socket(i,4444);
System.out.println(soc.getInetAddress());
BufferedReader is=new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataOutputStream os=new DataOutputStream(soc.getOutputStream());
BufferedReader bs=new BufferedReader(new InputStreamReader(System.in));
str=bs.readLine();
int i1=str.length();
strt=is.readLine();
os.writeChars(str);
os.write(10);//change made
System.out.println(strt);
os.flush();
is.close();
os.close();
soc.close();
}
}
//client side
import java.net.*;
import java.io.*;
class Serversoc1{
public static void main(String args[]) throws Exception
{
String str1=new String();
ServerSocket scos=new ServerSocket(4444);
Socket soc1=scos.accept();
System.out.println(soc1);
BufferedReader br=new BufferedReader(new InputStreamReader(soc1.getInputStream()));
DataOutputStream ds=new DataOutputStream(soc1.getOutputStream());
System.out.println("on server now");
str1= br.readLine();//change done
System.out.println(str1);// prints on the server side
ds.writeChars(str1);
ds.write(10);//change done
ds.flush();
br.close();
ds.close();
soc1.close();
}
}
it is still not working.please try it out.i've been working on it for a long time.but still ,if the message is not send back to the client
then it works properly the message is printed on the server side.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
In your client, you are still trying to read from the server Before you send the string to the server.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
anuj khanna
Greenhorn

Joined: Jan 11, 2001
Posts: 20
well sorry to say i've made the change still its not working.did u tried the code on machine.well it should be working still it isn't don't know where the problem lies.???
anuj khanna
Greenhorn

Joined: Jan 11, 2001
Posts: 20
well sorry to say i've made the change still its not working.did u tried the code on machine.well it should be working still it isn't don't know where the problem lies.???
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
As a matter of fact
The client

The Server

Blank lines and comments can help regardless of your level of understanding

------------------
Hope This Helps
Carl Trusiak
anuj khanna
Greenhorn

Joined: Jan 11, 2001
Posts: 20
thanks a lot.i'll keep it in mind.i'm highly grateful to you.thanks for taking the pain.
 
wood burning stoves
 
subject: still not solved
 
Similar Threads
problem in simple chat application.
Client server communication programme
simple socket program not working right
not able to connect...
sockets