Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Problem: Talking from Rebol to Rebol via socket

From: petr:krenzelok:seznam:cz at: 22-Feb-2009 11:51

Robert M. Münch napsal(a):
> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA384 > > Hi, to track down my problem with the communication between my DLL and Rebo > l via sockets I tried to create a Rebol only example. Looks like it has the > same problem. Here is my code (much simpler than the DLL code): > > === Server > rebol [] > > c-port: 12345 > listen: open join tcp://: c-port > > waitports: [listen] > > print "Listening:" > forever [ > ; wait until something happens > connection: wait waitports > > if same? connection listen [ > print [tab "Connected"] > > print [tab "Read message from c-side"] > c-client: first connection > wait c-client > print copy c-client > > print [tab "Send answer to c-side"] > insert connection "r-side" >
;------------------- Bug here - it should be - insert c-client. You can't insert into listening socket, just to derived connection channel. But - your script will not even get here. You use blocking synchronous communication. In this mode, it seems to me, that you stay stuck in the 'copy section, untill you close the connection on the other side. Hopefully it could be proved by checking the WireShark ... I don't use any other mode than open/direct/no-wait .... you have to be just carefull here - you need to "wait", or the program runs out ... In your while look, when reading out the data, you can receive empty result = no data, or none = other side closed the connection .... If you want better multiplexing, it would be probably better to build wait block, along with time interval, so you either get your processing by an event received from network, or time timeout .... Here's small examples: client: open/direct/no-wait tcp://localhost:9005 data: read %user.r forever [ print "Sending data" insert client data wait 5 ] ---------------------------- server: open/direct/no-wait tcp://:9005 conn: first wait server print "Got connection ..." forever [ wait conn while [not empty? data: copy conn][print ["Read: " length? data]] ] -pekr-