Hi again. I posted a question here a moment ago. It was about how to make a socket server in squeak. Basically it said that the I could use a kind of cross-recursivity or an infinite loop to re-call the waitForConnectionFor... method. But do you think there is a "standard" way to do this? Or shall I just use a mere infinite loop and each time tell the function to wait the biggest duration available (ie the largest integer I can write in this language).
Thanks in advance for helping.
François THIMON thimof@iutc3.unicaen.fr wrote:
the largest integer I can write in this language).
You might be surprised just how big that is; a LargePositiveInteger can be as big as memory (roughly, anyway) which on an OS with virtual memory etc can turn out to be awfully large.
Just for an amusing illustration, try
7000 factorial
and 'print it'. It will take a while, but nearly all the time is taken by the printing part. It's a 900+ byte LPI with 23878 digit decimal value
700 factorial is a lot smaller and faster to handle, being merely 1690 digits.
tim -- Tim Rowledge, tim@sumeru.stanford.edu, http://sumeru.stanford.edu/tim Avoid GOTOs completely if you can to keep the program readable.
Yes, but only certain values can be passed to some primitives since the primitives usually only understand 32 bit integers, Tim is pointing out integers can be much bigger than you think. In fact for this usage you can wait until the universe reaches heat death if you can keep a machine running that long, assuming the fix for delay where delay is a really big number is in the image you are using (Mantis bug 854).
I'll note a link to some old code, a server/client I wrote a few years back http://www.smalltalkconsulting.com/html/OTNotes3.html
The pattern here is to setup up a process that waits say 15 minutes for an connection to occur. If it occurs then we used a shared queue to place a work request object on. A lower priority task is waiting on the work queue and will then wake up and do what is required. As long as the stopRunning flag is not set we loop endlessly in this pattern. This allows us to easily terminate the listen process since it must wake up every 15 minutes (or what ever you choose) to check the flag and do other housekeeping.
buildListenProcess
self buildListenSocket. self listenProcess: ([[self stopRunning not] whileTrue: [self acceptRequests]] forkAt: Processor userInterruptPriority)
acceptRequests | request |
request _ self listenSocket waitForAcceptUntil: (Socket deadlineSecs: self secondsToWaitForListen). request isConnected ifTrue: [self incrementNumberIncoming. self incomingRequests nextPut: (JMMNetWorkRequest newWithSocket: request)]
secondsToWaitForListen ^15*60
buildListenSocket | server |
server _ Socket newTCP. server listenOn: self listenPort backlogSize: self backLogMessageSize. server isValid ifFalse:[self error:'Accept() is not supported']. self listenSocket: server.
On Apr 27, 2005, at 9:44 AM, Tim Rowledge wrote:
François THIMON thimof@iutc3.unicaen.fr wrote:
the largest integer I can write in this language).
You might be surprised just how big that is; a LargePositiveInteger can be as big as memory (roughly, anyway) which on an OS with virtual memory etc can turn out to be awfully large.
Just for an amusing illustration, try
7000 factorial
and 'print it'. It will take a while, but nearly all the time is taken by the printing part. It's a 900+ byte LPI with 23878 digit decimal value
700 factorial is a lot smaller and faster to handle, being merely 1690 digits.
tim
Tim Rowledge, tim@sumeru.stanford.edu, http://sumeru.stanford.edu/tim Avoid GOTOs completely if you can to keep the program readable.
-- ======================================================================== === John M. McIntosh johnmci@smalltalkconsulting.com 1-800-477-2659 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com ======================================================================== ===
Hi. First thanks for your guidance. Regarding the numbers, I already knew about their unlimited size, I still think it's not worse keeping those who can be handled more easily. Before, I thought there was a method I could use single instead of having to perform a loop just to do exactly the same wait.
Regarding your code, John, it seems to use the old class Socket (visibly some of the methods I looked for were only in the old class and the comments in the current squeak image haven't been updated and therefore still refer to them).
I tried to inspire myself from your code but it doesn't work more (I suppose I have to use the latest class for sockets). I tried to instantiate the class with newTCP as you do and I also tried to call Socket initializeNetwork (the "IfFailed:" part of the method has gone), I also tried Socket initialize but I whenever a connection is asked, I get message saying that the primitive called by primAcceptFrom: receiveBufferSize: sendBufSize: semaIndex: has failed.
Does someone know whether my code miss something or if I need to have a specific kind of client to get the server to work?? Thanks in advance.
On 4/28/05, François THIMON thimof@iutc3.unicaen.fr wrote:
Does someone know whether my code miss something or if I need to have a specific kind of client to get the server to work??
François,
The simplest way to get a server running is to install the KomServices package from SqueakMap, subclass TcpService, and override #serve:. Look on the class side to see how to start and stop a service on a particular port.
It's also good example code if that's what you're looking for.
Avi
squeak-dev@lists.squeakfoundation.org