On Thu, 13 Jan 2011, [email protected] wrote:
Thanks everyone for your responses. I studied the ConnectionQueue that Wilhelm pointed me to, that didn't clarify things for me too much and I wasn't able to get it working either. Finally Sven's version of the script got me going again. I can already see the first problem in the Xtreams implementation in that it uses non-blocking read in Socket>>readInto:, simply changing it to the blocking read doesn't seem to fix things though. Quite the opposite. So now I'm trying to zero in on the exact API at the Socket level to use. To expand on the test script a bit more, this is what I'd like to get going:| input output listener process sync | sync := Semaphore new. listener := Socket newTCP. listener listenOn: 9999 backlogSize: 10. process := [ [ input := listener waitForAcceptFor: 10. sync signal ] ensure: [ listener close ] ] fork. output := Socket newTCP. output connectToHostNamed: 'localhost' port: 9999. sync wait. [ output sendData: 'Hello!'; close. input receiveData. ] ensure: [ output close. input close. process terminate ]
It works fine in my Squeak image. Using localhost may be a problem if your local interface has an IPv6 address. Use 127.0.0.1 instead.
Levente
Maybe I need some other calls in the last block, but I'm stuck even earlier again. When I interrupt the script above, the debugger highlights the whole last block (the ensure: receiver) and there's just the top level UndefinedObject>>DoIt context. Doesn't make much sense to me but debuggers have bugs as well. I'm guessing the process is stuck on the sync wait before that. But the sync semaphore has excess signals 1. And what is even stranger is that input is still nil. How is that possible ? Can someone get the above going ? I realize that I deviated from Sven's version by moving the read out of the accept process, but that shouldn't be a problem, or am I missing something ? I'm also wondering if there is a Socket test suite somewhere that already contains tests like the above, that I could mine for examples. I don't see any in the PharoCore1.2 image. Thanks, Martin "Sven Van Caekenberghe"<[email protected]> wrote:| data input output listener socket1 socket2 process sync | data := #uninitialized. sync := Semaphore new. listener := Socket newTCP. listener listenOn: 9999 backlogSize: 10. process := [ [ socket1 := listener waitForAcceptFor: 10. socket1 waitForDataFor: 10. output := socket1 reading. data := output rest. sync signal ] ensure: [ listener close ] ] fork. socket2 := Socket newTCP. socket2 connectToHostNamed: 'localhost' port: 9999. input := socket2 writing. input write: 'Hello!'. sync wait. data asStringSven PS: Yes, Socket (and friends) have some pretty confusing API, you have to stick to what you know that works ;-)
