Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TCP/IP Message gets Appended with two dots...(Urgent)  RSS feed

 
Dushyant Bhardwaj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am working on a requirement where I am sendind a message
(underlying protocol used TCP/IP) using a program
developed using Java Sockets.
It sends the messgage on desired mechine and port but two dots(..)
gets appended with this message .
I am really not able to figure out from where these dots are coming ,
is it the network that appends these dots.

Any clue will be helpful.
An early response is highly appriciable.

Thanks and Regards
Dushyant Bhardwaj
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on where you are seeing the two dots they may just represent any unprintable character. Find a way to print out their values. I wonder if you're sending with println or something that tacks on carriage return & line feed. If you capture the message to a String, maybe see if trim() takes them off.
[ July 03, 2004: Message edited by: Stan James ]
 
Dushyant Bhardwaj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on where you are seeing the two dots they may just represent any unprintable character. Find a way to print out their values. I wonder if you're sending with println or something that tacks on carriage return & line feed. If you capture the message to a String, maybe see if trim() takes them off.

Hi,
Thanks for your response , I examined my code and found
1 output = new PrintWriter(socket.getOutputStream(),true);
2 output.println(Message);
I thinks line two is responsible for appending two dots at the end
because of println .
I tried using print in place of println but then it sends a null message
, What could be the aleternate solution for the same.

Thanks in advance.

Regards,
Dushyant Bhardwaj
 
Dushyant Bhardwaj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Further to previous posts , I found that two dots were because
of println which adds a carriage return and new line at the end.

Now the problem is when I am using print in place of println
my stream hangs and I don't get response immediately but get it only
after timeout.

This is how my approach is --

output = new PrintWriter(socket.getOutputStream(),true);
networkBin = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.print(Message);
output.flush();
socket.setSoTimeout(timeOut); //say time out is 60 secs
serverMsg = ""+networkBin.readLine();

Whare should I correct myself.
Any clue will be helpful.


Thanks & Regards,
Dushyant Bhardwaj
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now we see the client doing print and flush. Is the server doing the same with the response? If so, the client's readline() will wait for a crlf and never get it. With print & flush it may be hard for a receiver to distinguish the end of message from a slight network pause. If you have problems like that you might try sending the length before the message.
 
Dushyant Bhardwaj
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for comments but I didn't get what do you mean by -

"If you have problems like that you might try sending the length before the message."
Can you elborate it little more.

In my scenario server application is wriiten in "C" and doing something like print and flush , hence my readLine() keeps on waiting for the response because it does not get crlf.
Any other alternative for readLine() which can be used ?

Thanks & Regards,
Dushyant Bhardwaj
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, this is making sense. Right, readline() is waiting for crlf which never comes. Your alternative is to read available bytes until you reach the end of the response. And that's the hard bit. How do you know when you've read the end? You can get available byte counts from some streams, but that's not real reliable ... it may just mean there are none available right now because the network is having a bad moment, but there could be more in a sec. Can you recognize the end? Does the server send some kind of "fence" to let you know?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!