[R] read.socket utils package : somthing is going wrong
msalese
massimo.salese at gmail.com
Wed Apr 4 11:50:04 CEST 2012
Hi everyone,
I'd appreciate if someone could help me to understand what is happening.
I'm attempting to connect R to the broker platform using tcp on localhost
5333.
Just to learn how use make.socket, write.socket, ..functions I wrote simple
code:
#prepare string command to subscribe ask and bid price on Italian stock
#this should be a push stream like:
#First stream:
#outcome=OK|item=MI.EQCON.2552
#Update stream:
#MI.EQCON.1|21|10|22|11|23|12|24|5|20|19|7.5
#MI.EQCON.2552|||||||||||7.3
#..................................................
#until the buffer is full.
msg2<-'function=subscribe|item=MI.EQCON.1|schema=ask1;bid1'
#open socket connection
socketPointer<-make.socket(host='localhost',port=5333,fail=TRUE,server=FALSE)
#send the command line
write.socket(socket=socketPointer,string=msg2)
#read data
read.socket(socket=socketPointer,maxlen=252,loop=FALSE)
#send command to unsuscribe
write.socket(socket=sockPointer,string=unsub)
#close socket
close.socket(sockPointer)
The code remain stick on read.socket function, so I decided to use debug
functionality:
This is the read.socket source:
debugging in: read.socket(socket = s.p, maxlen = 252, loop = FALSE)
debug: {
if (length(port <- as.integer(socket$socket)) != 1L)
stop("invalid 'socket' argument")
maxlen <- as.integer(maxlen)
buffer <- paste(rep.int("#", maxlen), collapse = "")
repeat {
tmp <- .C("Rsockread", port, buffer = buffer, len = maxlen,
PACKAGE = "base")
rval <- substr(tmp$buffer, 1L, tmp$len)
if (nzchar(rval) || !loop)
break
}
rval
}
everything works fine up to .C("Rsockread", port, buffer = buffer, len =
maxlen, PACKAGE = "base")
when execution arrive to the c function call R goes in a some kind a eternal
loop !
Thanks very much
Massimo Salese
--
View this message in context: http://r.789695.n4.nabble.com/read-socket-utils-package-somthing-is-going-wrong-tp4531374p4531374.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list