Lalas, I am also trying to do what you are trying to do, as a complete know-how for sockets. tdsmith in chat #R freenode gave me the right advice: use telnet .
So, terminal 1 window:
R s = socketConnection(port=12345, server=T)
R should be visible now (expecting someone to talk to him).
Now open another terminal window and enter:
telnet localhost 12345
Return to window 1. You will see that R no longer hanging. Good! So now enter (in the same window 1):
readChar(s,3)
Return to window 2, telnet window. Type of:
Lalas wins at life.
In window 1, you will see that text entered somewhere outside of window 1 introduced window 1.
Lal
Unfortunately, readChar expecting a shorter message, so you did not receive all of this. Try readChar(s,6) again and you will hear
as win
. You will notice that readChar(s,1) hears letters that seem to βhang thereβ (where?). Weird But obviously this is an annoying way to listen in order to pre-specify the length of the message!
Try readLines(s) , which does not need specification; he is waiting for the symbol EOL .
Return to window 2, telnet window:
Money that what I want that what I waaaaaaaant
The only way I could get readLines(s) to hear me was Ctrl ] 'ing in telnet to get an invitation, and then close ing. R will not hear all these new lines (even if you type \r\n , etc.), but as soon as the connection is closed, you will get each line in window 1.
Now we use the extra help from ernst in the same freenode room. Instead of using telnet this time using nc localhost 12345 . Netcat can hear and speak and behave more expectedly, because I can send EOL with Ctrl D.
Close and reopen window 1 of the socket connection s = socketConnection(port=12345,server=T) . Close telnet in window 2 and enter nc localhost 12345 instead. Now enter messages on both sides, and they can be received by each other.
window 1:
cat( rpois(1e2, 20), file=s) readLines(s)
window 2 (some random numbers must have heard):
Lalas wins at life. {{control D}}
A message should now appear in window 1.