• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

small problem on Java socket

 
cheng waiwai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2991
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50284
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And where do you have the exception? Please supply full details, so we can help.
 
cheng waiwai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 982
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 982
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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。。
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic