CTRL-M (^M) characters in data read from sockets

Hi,

We have developed a software applications which opens upto 300 TCP connections and 4000 UDP sockets. The data from the TCP application is multiplexed to UDP sockets and viceversa.

We connect to the application using a TCP socket and send certain data to the application which in turns sends this data to all the 4000 UDP sockets. The data received from 4000 UDP sockets is in turn sent back to the TCP socket as responses.

We used telnet to connecct to thespecific TCP port on our application, sent a request to be sent to all 4000 UDP sockets and noticed ctrl-M characters in the data received from TCP socket. However we are sure we are not appending or adding this ctrl-m character while sending the data on TCP socket.

telnet host port >/tmp/abc

send a request

send next request

(after 10 mins, close connection)

cat -vet /tmp/abc >/tmp/xyz

There are ctrl-m characters in /tmp/xyz.

^M is observed only at the end of few lines and not on all lines. Successive repeatition of this test generates ^M in different lines but at the end of the line always.

Can anybody help me to know why these ^M characters are getting generated?

Note: We are completely working on Solaris and do not move contents across Windows and Unix. Our application is completely written on C++

Thanks.

Message was edited by:

shekhnam

[1417 byte] By [shekhnama] at [2007-10-3 2:16:15]
# 1
The newlines are coming from telnet, or the lines you are typing into telnet. I would have said they should be there on all lines, not just some. Alternatively you have a bug in your code. TCP/IP certainly doesn't introduce data into the stream.
ejpa at 2007-7-14 19:15:06 > top of Java-index,Archived Forums,Socket Programming...
# 2
When the same output is captured from the telnet session ^M appears in few places, where as if i open a new TCP socket connection and forward the console output to some file( application > /tmp/output) ^M appears in all the lines. can you please help us to resolve this problem.
saravananma at 2007-7-14 19:15:06 > top of Java-index,Archived Forums,Socket Programming...
# 3

They are coming from Telnet. If Telnet is your chosen client, you have also therefore chosen to get the newlines it generates, and you will just have to remove them yourself at the receiver. If Telnet is just being used temporarily during development, the problem will disappear when you write your real client.

ejpa at 2007-7-14 19:15:06 > top of Java-index,Archived Forums,Socket Programming...
# 4

Thanks for your quick response

In older application we used multiple sockets, where as in new application we use one socket to read all the data, this was done to use the inherient property of solaris 2.8. The load is much higher on the new application (11KB/Sec) where as in older application it was less(2KB/Sec) we couldn't find any ^M on older application, does heavy load make any difference in telnet to add a newline character.

saravananma at 2007-7-14 19:15:06 > top of Java-index,Archived Forums,Socket Programming...
# 5
Nope.You haven't said exactly how you're using Telnet, but if you're typing into it every time you hit ENTER you'll get a newline in the output. If you're feeding it from a file I don't know what it will do - it might insert a newline every 80 characters or something like
ejpa at 2007-7-14 19:15:06 > top of Java-index,Archived Forums,Socket Programming...
# 6

We send a request only one time from the telnet session to our application, the response comes from our application for 20 seconds. Also we forward the output to a file( telnet host port > outputfile). When the samething is done using our own application we find ^M character( application host port > ownoutput) in all the lines. Where as in previous (telnet) case we could find very few ^M characters. Can there be any problem of forwarding the telnet output directly to a file (telnet host port > file).

saravananma at 2007-7-14 19:15:06 > top of Java-index,Archived Forums,Socket Programming...
# 7

I think I've misunderstood something here. The problem you're having is with the response being filtered by Telnet or your client, not what telnet is sending to the server?

In that case I think the explanation is clear. Telnet is trying to display what comes back on a screen, and it is deleting and inserting newlines every now and then according to its internal whim so as to make the data wrap. I don't know if you can control that, but I also don't know if it matters as long as you have your own client application. You just have to stop treating Telnet as a viable test client.

ejpa at 2007-7-14 19:15:06 > top of Java-index,Archived Forums,Socket Programming...