aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes TCP/IP Message gets Appended with two dots...(Urgent) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "TCP/IP Message gets Appended with two dots...(Urgent)" Watch "TCP/IP Message gets Appended with two dots...(Urgent)" New topic
Author

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

Dushyant Bhardwaj
Greenhorn

Joined: Apr 18, 2004
Posts: 28
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

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dushyant Bhardwaj
Greenhorn

Joined: Apr 18, 2004
Posts: 28
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

Joined: Apr 18, 2004
Posts: 28
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

Joined: Jan 29, 2003
Posts: 8791
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

Joined: Apr 18, 2004
Posts: 28
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

Joined: Jan 29, 2003
Posts: 8791
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?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: TCP/IP Message gets Appended with two dots...(Urgent)
 
Similar Threads
JDBC for Android not connecting
protocol used by Socket!!!
Counting Dots
basic questions (FileInputStream)
sending xml over tcp/ip