• Post Reply Bookmark Topic Watch Topic
  • New Topic

When will BufferedReader.ready() status will be true  RSS feed

 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello memebers
i am actually trying to implement a Server Client communication using the RTP and UDP protocols, i am trying to send the message from the client to server using BufferedReader and BufferedWriter the problem i am facing is even though the client and server are bind same port the server is unable to read what the client is try to say.
that means BufferedReader Object is unable to read the String, i checked status of the BufferedReader Object using ready() it is returning false, so when will the object status change to true.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Check if a flush() is being done on the BufferedWriter side, each time the message has been readied for dispatch.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no not before the object is reading the line.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Saw this line just now:
...client and server are bind same port ...

May not be related to the problem, but am curious: why the same port? Are you using setReuseAddress()?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would avoid using ready() at all - it's extremely unreliable. When it returns false, there's no way to tell the difference between false because the stream is closed, and false because the data simply hasn't been sent yet. Just use one of the read methods - they will either block until something happens, or return -1 or null if the stream is closed.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:When it returns false, there's no way to tell the difference between false because the stream is closed, and false because the data simply hasn't been sent yet. Just use one of the read methods - they will either block until something happens, or return -1 or null if the stream is closed.


i am using obj.readLine() but still the it is unable to read any string.
can you explain a bit elaborate way.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Something seems odd here: Since you mention it's UDP, I'd have thought you'd be using DatagramSocket and sending/receiving DatagramPacket instances. How is BufferedReader coming into picture? Is it possible to post your code?
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ofcourse for sending and receiving the datagram packets i am using DatagramPacket and DatagramSocket, but inorder to know which particular packet to be sent @ which time will be requested by the client and that message is being done through this buffered read/write.
the code is looks quite lengthy one and even to take look @ its inter related code will become more number of lines, if you need i will post the code which is only of this requirement but i need some time to do it.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
client
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If you're passing the contents of a string as plaintext, then ensure that you append a newline character at the end, on the writer side. readLine() blocks until it encounters a newline character.

That's all I can think of at the moment.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
server


here RequestLine dosen't get any thing means RTSPBufferedReader.readLine() dosen't read anything.
RTSPBufferedReader.ready() is false
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I think it's because newline is not being appended by the client. Try appending a newline.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankQ it worked
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!