[Rd] Problems Reading from Socket
mschaff at bu.edu
Fri Jul 21 22:24:49 CEST 2006
My followup question went unanswered in another thread, so I thought
I'd start a new one and rephrase it.
I need to use CGI POST to retrieve data from a server, so thanks to
Duncan's suggestion, I used the httpRequest package as example code
for doing so. BUT, I have another problem. The data retrieved from
the socket has occasional problems. I include example code below to
demonstrate the problem. The problems occur in R v2.3.1 (2006-06-01)
on both Linux and OS X.
For comparison, here is code that produces the correct output (I used
paste on the URL to prevent word-wrapping from clobbering it):
To reproduce the incorrect results, the socket-based code is:
len <- length( strsplit(dat,"")[])
request<-paste("POST ",path," HTTP/1.1\nHost: ",host,
fp <- socketConnection(host=host,port=80,server=FALSE,blocking=TRUE)
socketSelect(list(fp)) # Wait until results are ready
So my question is why do I get lines that are split up by hexadecimal
characters (e.g. element 13 -- 'a1'-- splits what should be one line:
lines 12 + 14)? Am I misunderstanding what is needed to correctly
read from a socket or is this a bug? Can anyone offer assistance?
More information about the R-devel