On 24 Feb 2012, at 15:42, Göran Krampe wrote:

> On 02/24/2012 02:28 PM, Tudor Girba wrote:
>> Hi Sven,
>> 
>> Thanks, but I did not explain my problem correctly. My problem is
>> actually super trivial. I have a server that throws continuously plain
>> text (actually, it's a logging facility), and I need to implement a
>> client that connects to it and consumes the plain text endlessly
>> without any feedback to the server. So, essentially, there is no
>> communication protocol involved.
> 
> Just use SocketStream. Since you are building a client it is trivial:
> 
> stream := SocketStream openConnectionToHostNamed: host port: port.
> [stream isConnected] whileTrue: [
>       line := stream nextLineLf]
> 
> ...or something like that (just see protocol of SocketStream). No need to use 
> Socket directly - I tend to keep repeating that on mailinglists. :)
> 
> For a trivial *forking server* you can load Blackfoot from SS and "copy" from 
> it, it is a stripped down server basically.
> 
> regards, Göran

He wants a server, I think. 

Here is an example of a very simple forking server, without error handling code:

| serverSocket serverProcess |
serverSocket := Socket newTCP.
serverSocket listenOn: 8888 backlogSize: 5.
serverProcess := [ 
 [ | clientSocket stream line |
        clientSocket := serverSocket waitForAcceptFor: 900.
        stream := SocketStream on: clientSocket.
        [ [ (line := stream nextLine) ~= 'quit' ] whileTrue: [
                Transcript crLog: line.
                stream nextPutAll: line reverse; crlf; flush ].
        stream close ] fork.
 ] repeat 
] fork.
{ serverProcess. serverSocket }.

And here is how it works:

$ telnet 127.0.0.1 8888
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello
olleh
doru 
urod
smalltalk
klatllams
quit
Connection closed by foreign host.

Make sure to inspect the code above, so that you can #terminate the server 
process and #close the server socket. The process browser is useful too (don't 
forget to update it), as will be

 Socket allInstances

and/or

 Socket allInstances do: #close

(Warning: you will crash/hang your image until you get this 100% right with 
proper error handling.)

HTH,

Sven

--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill

Reply via email to