On Tue, Oct 31, 2006 at 12:43:47PM +0100, Robin Redeker wrote:
> Hi,
>
> in the attachment there is a piece of code, which establishes a tcp
> connection to a listening socket and reads all arriving data from there.
And as usual i forgot the attachment...
"Filed out from GNU Smalltalk version 2.2b on 31-Oct-2006 12:27:04"!
PackageLoader fileInPackage: #TCP!
Object subclass: #Communicator
instanceVariableNames: 'host port thread buffer '
classVariableNames: ''
poolDictionaries: ''
category: nil!
Communicator comment:
'This is the main Communicator class, it handles a connection with a
communicator server
which serves as a gateway to multiple chat and instant messaging services.'!
!Communicator class methodsFor: 'instance creation' copy!
new: host port: port
^(self basicNew) host: host; port: port; initialize
! !
!Communicator methodsFor: 'initialization' copy!
host: nHost
^host := nHost!
port: nPort
^port := nPort!
initialize
| socket |
('started communicator on ', host, ':', (port printString)) displayNl.
socket := TCP.Socket remote: host port: port.
socket isNil ifTrue: [ ^self error: 'couldn''t create socket!' ].
socket nextPutAll: 'Hello!'. socket nl. socket flush.
thread := [
[ socket isPeerAlive ] whileTrue: [
| hunk |
hunk := socket nextHunk.
('read hunk [', hunk, ']') displayNl.
].
'End!' displayNl
] fork
! !
Smalltalk at: #x put: (Communicator new: 'localhost' port: 1234)!
[ Processor yield ] repeat!
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk