Sending "\n" in socket programming

Hi I am doing a socket programming, I want to send a string with
multiple lines, i.e. it contains “\n”.
What I did:
a=“Hi”
a+="\n"
a+=“there”
if I send ‘a’ over socket, I get only “Hi”, could you suggest me any
plateform independent solution? Atleast which works for windows and
ubuntu.

I tried replacing “\r\n” for “\n” but its behaving in the same way.
Interestingly I wrote a small program just to check, but that program is
working. What is the way people send newline over socket?

On Mon, Sep 24, 2012 at 1:40 PM, ajay paswan [email protected]
wrote:

Hi I am doing a socket programming, I want to send a string with
multiple lines, i.e. it contains “\n”.
What I did:
a=“Hi”
a+="\n"
a+=“there”

That can be simplified to

a = “Hi\nthere”

if I send ‘a’ over socket, I get only “Hi”,

There are two potential reasons for that:

  1. you do not append a trailing newline (e.g. by using #puts on the
    socket).
  2. the reader just reads a single line

could you suggest me any
plateform independent solution? Atleast which works for windows and
ubuntu.

See above.

I tried replacing “\r\n” for “\n” but its behaving in the same way.
Interestingly I wrote a small program just to check, but that program is
working. What is the way people send newline over socket?

Please post the program (or share it via github or a pastebin).

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs