File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes small problem on Java socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "small problem on Java socket" Watch "small problem on Java socket" New topic
Author

small problem on Java socket

cheng waiwai
Greenhorn

Joined: Jan 26, 2013
Posts: 7
Do not ask my client cannot read the data returned from the server-side?,usera is the client,userb is the server






Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2249
    
  47
Welcome to the Ranch.

Please UseCodeTags (← click) when posting code as it makes it easier for people to read your code. I've added them for you this time.
Also please TellTheDetails (← click). Posting 300+ lines of code with little to no explanation of what is happening or is supposed to happen makes it hard for people to help you.
cheng waiwai
Greenhorn

Joined: Jan 26, 2013
Posts: 7
Tony Docherty wrote:Welcome to the Ranch.

Please UseCodeTags (← click) when posting code as it makes it easier for people to read your code. I've added them for you this time.
Also please TellTheDetails (← click). Posting 300+ lines of code with little to no explanation of what is happening or is supposed to happen makes it hard for people to help you.




usera Cannot read userb return values。。。。Is the value returned by the server-side, the client cannot read
cheng waiwai
Greenhorn

Joined: Jan 26, 2013
Posts: 7
cheng waiwai wrote:
Tony Docherty wrote:Welcome to the Ranch.

Please UseCodeTags (← click) when posting code as it makes it easier for people to read your code. I've added them for you this time.
Also please TellTheDetails (← click). Posting 300+ lines of code with little to no explanation of what is happening or is supposed to happen makes it hard for people to help you.




usera Cannot read userb return values。。。。Is the value returned by the server-side, the client cannot read


but my no found nullpointexception;;;;
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38480
    
  23
And where do you have the exception? Please supply full details, so we can help.
cheng waiwai
Greenhorn

Joined: Jan 26, 2013
Posts: 7
Campbell Ritchie wrote:And where do you have the exception? Please supply full details, so we can help.


my jdk is1.7,,I have window when server b,so,don't konw why I canont fount the exception...I am sorry.. My English is not good ... You might read difficult
cheng waiwai
Greenhorn

Joined: Jan 26, 2013
Posts: 7
cheng waiwai wrote:
Campbell Ritchie wrote:And where do you have the exception? Please supply full details, so we can help.


my jdk is1.7,,I have window when server b,so,don't konw why I canont fount the exception...I am sorry.. My English is not good ... You might read difficult



and I do not know why my client will read the value to the value returned by the server is empty
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5


available() tells how many byte are readable at the moment without blocking.

Sockets do not preserve "message boundaries": if you write "n" bytes, the receiving party can not forcibly read them all at once.

available() is rarely needed and rarely used right.
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
You use the platform default encoding to convert a string into a byte stream and back. If they happen to differ at the sending and receiving sides, this will be a problem.

You might have a look at java.io.DataOutputStream.writeUTF and java.io.DataInputStream.readUTF.

cheng waiwai
Greenhorn

Joined: Jan 26, 2013
Posts: 7
Ivan Jozsef Balazs wrote:

available() tells how many byte are readable at the moment without blocking.

Sockets do not preserve "message boundaries": if you write "n" bytes, the receiving party can not forcibly read them all at once.

available() is rarely needed and rarely used right.


I see, so the bytes have been read as empty
cheng waiwai
Greenhorn

Joined: Jan 26, 2013
Posts: 7
Ivan Jozsef Balazs wrote:You use the platform default encoding to convert a string into a byte stream and back. If they happen to differ at the sending and receiving sides, this will be a problem.

You might have a look at java.io.DataOutputStream.writeUTF and java.io.DataInputStream.readUTF.



thanks,I have read theAPI document, and think this is convenient,,thanks。。
 
 
subject: small problem on Java socket