Re: [R] Sending a null byte to a socket

From: Dan Tenenbaum <>
Date: Thu, 24 Jun 2010 10:41:26 -0700

Sorry to spam the list again, but I was wondering if anyone has a solution to this. It seems that writing nulls to sockets is a pretty common use case, so I would hope there is a way to do this. Thanks.

On Wed, Jun 16, 2010 at 12:52 PM, Dan Tenenbaum <> wrote:

> Hello,
> I am trying to write some code in R to communicate over sockets via the
> STOMP protocol (
> As you can see, a null byte (ASCII 0) is used as the "over" signal.
> I'd like to be able to do something like this:
> write.socket(socket, "CONNECT\nlogin: me\npasscode: pass\n\n\000")
> However, R does not like it when you put "\000" in a string:
> > "\000"
> Error: embedded nul in string: '\0'
> I thought perhaps that write.socket would automatically send a null byte,
> but it doesn't appear to.
> I'm getting similar results with socketConnection() and writeLines(). I
> thought that writeBin() might be the solution but it gives me:
> Error in writeBin(n, con) : can only write to a binary connection
> I'm not clear how to make my socket a binary connection.
> I am only going to be writing strings, with the exception of these null
> bytes. Can anyone suggest a method for doing this?
> Thanks
> Dan

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 24 Jun 2010 - 17:45:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jun 2010 - 18:30:36 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive