• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

read() and write() method of socket channel did not work fine for huge data

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have implemented socket channel for client server application.
That program works fine when i am sending data of 10000 characters but when I am sending data of more than 50000 characters, then that program did not work fine.
For sending data I am using
String message = "my own data"+"\n"
ByteBuffer buf = ByteBuffer.wrap(message.getBytes());
SocketChannel.write(buf);

And for recieving tha data I am using
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
br.readLine();

My server is in socket channel and client is simple socket.


Thanks
Sunil
sunil.sahoo@artificialmachines.com
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "did not work fine"? You need to Tell The Details
 
sunil sahoo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I mean that I can not read the whole data only I can read a part of data while C, C++ people can get the whole data.
So how to read the data using TCP socket in JAVA if the data is so long
Thanks
Sunil
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no limitation to the amount of data that can be written to a stream/socket/channel.
I'm sorry, but I don't have much experience with NIO. Have you tried with streams? That I can help with.
 
sunil sahoo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi As per our discussion I have changed my whole code into simple socket. There is no NIO now.
Means now it is on stream.
Both server and client work on socket only.

Here also I faced the same problem I can read and write a string of maximum 20,000 characters but i want to read and write more data without using filereader writer.

Thanks
Sunil

 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're going to have to show us some code. As I said before, there is no limitation to the amount of data you can read/write with a stream.
Is your code failing without error or are you getting an exception (if you are, what is it)?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried sending huge data and i am successful in receiving it. There are problems when the buffer is full.

You can try using flush command.

and along with it you read byte by byte it might help like shown in

http://techtadka.net/articles/programming/203-how-to-read-and-write-data-from-socket-in-java.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic