• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to know the number of received bytes  RSS feed

 
Suresh Khant
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ,

I am trying to write a server socket program which receives Packet ( which contains of array of bytes) from the client and reply to the client , the problem is that size of the client's packet ( no of bytes ) will be varied every time and there is no indicator for the end of the packet , so is there any way to solve this issue ,

by the way i have tried something like


or



but they dont work
 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use DataOutputStream to write, DataInputStream to read. That way, you can use writeInt to first write the number of bytes, then write that many bytes. On the other side you can use readInt to first read the number of bytes, then read that many bytes. In short:
 
Suresh Khant
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob for your reply ,

Use DataOutputStream to write, DataInputStream to read. That way, you can use writeInt to first write the number of bytes, then write that many bytes.

You mean writing in the client side , by the way the client machine is a device manufactured by third party and so i can not do anything from client side .

All the code will be At server side . nothing to be done at the client side.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!