'From Squeak 1.22 of September 21, 1997 on 1 October 1997 at 9:28:59 pm'! Connection subclass: #ChatServer instanceVariableNames: '' classVariableNames: 'Chat Clients ServerAddress UserName ' poolDictionaries: '' category: 'Connections'! !ChatServer methodsFor: 'forReflector' stamp: 'MJG 9/29/97 09:55'! addClient: someone Clients at: someone put: (Connection to: someone port: 1980).! ! !ChatServer methodsFor: 'forReflector' stamp: 'MJG 9/29/97 11:06'! tellAll: message but: sender Clients keys do: [:client | (client = sender) ifFalse: [[(Clients at: client) nextPut: message] on: ConnectionError do: [Transcript show: 'Error on: ',client ; cr. Clients removeKey: client ifAbsent: [].] ]]. ! ! !ChatServer methodsFor: 'from connection' stamp: 'mjg 10/1/97 21:28'! eventRead: aString | otherSide | "Transcript show: 'Got something!!' ; cr." otherSide _ self remoteAddress. (Clients includesKey: otherSide) ifFalse: [self addClient: otherSide]. "Transcript show: 'Passing on what I got'; cr." self tellAll: aString but: otherSide. "Transcript show: 'Adding what I got'; cr." self class addToChat: aString.! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! ChatServer class instanceVariableNames: ''! !ChatServer class methodsFor: 'forUI' stamp: 'mjg 10/1/97 21:07'! addToChat: aString Chat _ Chat , (Character cr) asString, aString. self changed: #value. ! ! !ChatServer class methodsFor: 'forUI' stamp: 'mjg 10/1/97 10:57'! connect ServerAddress _ (FillInTheBlank request: 'Connect to whom?' initialAnswer: 'Your Server') asDottedAddress. self sendToServer: 'A new connection from ', UserName. ! ! !ChatServer class methodsFor: 'forUI' stamp: 'mjg 10/1/97 15:04'! contents ^Chat! ! !ChatServer class methodsFor: 'forUI' stamp: 'mjg 10/1/97 21:20'! sendChat | someText | someText _ FillInTheBlank request: 'Send what text?' initialAnswer: ''. "Transcript show: 'Adding to myself',someText ; cr." self addToChat: someText. "Transcript show: 'Adding to Server', someText ; cr." self sendToServer: UserName,' says ', someText. "Transcript show: 'Adding to All', someText ; cr." self tellAll: UserName,' says ', someText. ! ! !ChatServer class methodsFor: 'forUI' stamp: 'mjg 10/1/97 21:21'! sendToServer: aString | c | (ServerAddress = '') ifFalse: [c_Connection to: ServerAddress port: 1980. c nextPut: aString. c close.] ! ! !ChatServer class methodsFor: 'forUI' stamp: 'mjg 10/1/97 21:07'! tellAll: message "Transcript show: 'Telling all'; cr." Clients keys do: [:client | [(Clients at: client) nextPut: message] on: ConnectionError do: [Transcript show: 'Error on: ',client ; cr. Clients removeKey: client ifAbsent: [].] ]. ! ! !ChatServer class methodsFor: 'forUI' stamp: 'mjg 10/1/97 15:01'! value ^Chat! ! !ChatServer class methodsFor: 'initialize' stamp: 'mjg 10/1/97 14:26'! startService Socket initializeNetwork: 0. self service: 1980. UserName _ FillInTheBlank request: 'Your name?' initialAnswer: ''. Clients _ Dictionary new. ServerAddress _ String new. Chat _ String new. self breakDependents. "Give up old UI" ChatView new openOn: self. ! ! !ChatServer class methodsFor: 'initialize' stamp: 'mjg 10/1/97 09:50'! stopService super stopService. Clients isNil ifFalse: [Clients keys do: [:client | [(Clients at: client) close] on: ConnectionError do: ["Nothing"] ] ] ! !