[R] Socket Connection in R

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jul 2 09:17:08 CEST 2014


On 01/07/2014 13:37, Param Jeet wrote:
> I am trying to create socket connection in R.

That is not a 'socket connection'.  I suggest you use one instead: see 
?socketConnection.

>
>      socket <- make.socket("localhost",2099,T,T)
>      msg2<-'function=subscribe|item=MI.EQCON.1|schema=last_price;ask;bid'
>      write.socket(socket,msg2)
>      read.socket(socket,252,FALSE)
>
> When I run the read.socket line, I get error:
>
>      Error in read.socket(socket, 252, FALSE) :
>      embedded nul in string:
> 'þþ-\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\001\0\004\0CTCL\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'
>
> I am Unable to solve this problem. Please advice how to get rid of this
> issue.

The help says

      ‘read.socket’ reads a string from the specified socket,

'Strings' do not have embedded nulls: you need something which can do 
binary reads.  For that you need to use connections.

>
>
> Regards,
>
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list