• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

how to know the number of received bytes

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic