[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] Smalltalk MUD
From: |
kraehe |
Subject: |
[Help-smalltalk] Smalltalk MUD |
Date: |
Sat, 28 May 2005 16:14:20 +0200 |
User-agent: |
Mutt/1.5.9i |
Moin Guru's,
i'm currently playing around with GNU Smalltalk, and the toy project
is a Smalltalk MUD. A MUD is a multi user telnet server, where people
can login, chat and interact on a ruleset in a given world. The people
might be players, who can just use the world, builders who can extend
the world but not change the rules and coders who can also change the
rules. I've deceided for GST because of freedom and because GST does
not require a GUI to run.
My first try with inheriting from NetClients.NetServer failed badly,
so I started with a striped down cut'n'paste of it. I'm currently
stuck with the problem, that either input (FileStream>>next) or
ServerSocket>>waitForConnection hangs. So I can telnet to the server
type a line, perhaps two, but sequent lines are ignored because
something hangs in process scheduling. I currently dont know, if
I'm doing something completely wrong, or do I expect a feature that
never been implemented: an accept/select loop to manage cooperative
co-processing ?
st> FileStream fileIn: 'SmallMUD.st'!
st> MUD.MUDServer new port: 4321; start!
'register server socket'
'waiting for connection'
telnet localhost 4321 - nothing happens on the gst screen, but
st> 123!
evaluting something, will yield the co-process
'accepting connection'
'waiting for connection'
now typing something into telnet window does nothing, but
st> 1!
evaluting something, will yield the co-process
'>$t'
'>$e'
'>$s'
'>$t'
'>$
'
'>$
'
st> Processor activeProcess suspend!
now the console is gone, so i can no longer interact, but the
behavoir does not improve much. I can login, type a line that
is shown, perhaps also some more, but suddenly the console stops
typing, till i login an other time to kick the waitForConnection
co-process. Ok - here comes the code - its broken - but why ?
" -------------------------------------------------------------------
MUD.MUDServer (c) 2005 Michael Koehne / GNU General Public License
------------------------------------------------------------------- "
Object
subclass: #MUDSocket
instanceVariableNames: 'process socket'
classVariableNames: 'priority'
poolDictionaries:'TCP'
category: 'MUD-Collection'
!
MUDSocket
subclass: #MUDServer
instanceVariableNames: 'port'
classVariableNames: 'servers'
poolDictionaries:'TCP'
category: 'MUD-Collection'
!
MUDSocket
subclass: #MUDClient
instanceVariableNames: 'user'
classVariableNames: 'clients'
poolDictionaries:'TCP'
category: 'MUD-Collection'
!
!MUDSocket class methodsFor: 'initialization'!
initialize
priority := Processor highIOPriority.
"userSchedulingPriority lowIOPriority"
MUDServer initialize.
MUDClient initialize
! !
!MUDServer class methodsFor: 'initialization'!
initialize
servers := Dictionary new
! !
!MUDClient class methodsFor: 'initialization'!
initialize
clients := Dictionary new
! !
!MUDSocket methodsFor: 'accessing'!
priority
^ priority
!
socket: s
socket := s
!
socket
^ socket
!
process: p
process := p
!
process
^ process
! !
!MUDSocket methodsFor: 'logging'!
log: s
s printNl
! !
!MUDServer methodsFor: 'accessing'!
servers
^ servers
!
port: p
port := p
!
port
^ port
!
name
^ 'listenTo:', port printString
! !
!MUDClient methodsFor: 'accessing'!
clients
^ clients
!
user: u
user := u
!
user
^ user
!
name
^ 'client'
! !
!MUDSocket methodsFor: 'running'!
start
process := [ self run: self name ] forkAt: priority
!
stop
process notNil ifTrue:
[ process terminate.
process := nil.
self finish ]
!
run: aProcessName
Processor activeProcess name: aProcessName.
self run
! !
!MUDServer methodsFor: 'running'!
run
socket notNil ifTrue: [ ^ socket ].
self log: 'register server socket'.
socket := ServerSocket port: port.
servers at: port put: self.
[ self log: 'waiting for connection'.
socket waitForConnection.
self log: 'accepting connection'.
MUDClient new socket: socket accept; start.
] repeat.
self finish
!
finish
servers removeKey: port.
socket notNil ifTrue: [ self socket close ].
socket := nil.
! !
!MUDClient methodsFor: 'running'!
run
| s |
clients at: socket put: self.
[ s := socket next.
s isNil ifTrue: [ ^ self finish ].
self log: '>', (s printString).
] repeat.
self finish
!
finish
socket notNil ifTrue: [
clients removeKey: socket.
socket close.
].
socket := nil.
! !
MUDSocket initialize!
" ------------------------------------------------------------------- "
bye Michael
--
mailto:address@hidden UNA:+.? 'CED+2+:::Linux:2.4.29'UNZ+1'
http://www.xml-edifact.org/ CETERUM CENSEO WINDOWS ESSE DELENDAM
- [Help-smalltalk] Smalltalk MUD,
kraehe <=