WebSockets

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

WebSockets

Bernat Romagosa
Hi list,

I've installed the latest version of WebClient from the metacello configuration, and when I run WebSocket example I get the following output in the Transcript:

New WebSocket(127.0.0.1:33022)
WebSocket(127.0.0.1:33022)

Which I guess is alright, but then if I access localhost:8080 I get the following:

ConnectionClosed: Connection closed while waiting for data.
[ConnectionClosed signal: 'Connection closed while waiting for data.'] in Socket>>waitForDataFor:
Socket>>waitForDataFor:ifClosed:ifTimedOut:
Socket>>waitForDataFor:
Socket>>receiveDataSignallingTimeout:into:startingAt:
SocketStream>>receiveData
SocketStream>>next
WebSocket>>readMessage
[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil] in [[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil]
on: Error
do: [:ex | self handleError: ex]] in WebSocket>>run
BlockClosure>>on:do:
[[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil]
on: Error
do: [:ex | self handleError: ex]] in WebSocket>>run
BlockClosure>>ensure:
WebSocket>>run
[:req | 
| ws |
ws := req asWebSocket.
ws timeout: 300.
Transcript cr; show: 'New ' , ws.
ws
onMessage: [:data | mutex
critical: [sockets
do: [:s | s send: data]]].
ws
onClose: [Transcript cr; show: 'Closing ' , ws.
mutex
critical: [sockets
remove: ws
ifAbsent: []]].
ws
onError: [:ex | 
Transcript cr; show: ws.
Transcript cr; show: ex description.
Transcript cr; show: ex signalerContext longStack].
mutex
critical: [sockets add: ws].
ws run] in WebSocket class>>example
WebServer>>invokeAction:request:
[self
invokeAction: (action at: 2)
request: request] in WebServer>>dispatchRequest:url:
BlockClosure>>on:do:
WebServer>>dispatchRequest:url:
WebServer>>dispatchRequest:
[| ssl |
certName
ifNil: [stream := SocketStream on: aSocket]
ifNotNil: [ssl := Smalltalk
at: #SqueakSSL
ifAbsent: [self error: 'SqueakSSL not installed'].
stream := ssl secureSocketStream on: aSocket.
[stream sslAccept: certName]
on: Error
do: [^ stream destroy]].
[aSocket isConnected]
whileTrue: [stream peek
ifNil: [^ aSocket destroy].
request := self newRequest.
[request readFrom: stream]
on: Error
do: [:ex | 
(ex isKindOf: NetworkError)
ifFalse: [[request send400Response]
on: Error
do: [:ignore | nil]].
^ aSocket destroy].
self dispatchRequest: request].
nil] in WebServer>>handleConnectionFrom:
BlockClosure>>on:do:
WebServer>>handleConnectionFrom:
[self handleConnectionFrom: aSocket] in [[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]] in [[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
BlockClosure>>on:do:
[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]] in [[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
BlockClosure>>ensure:
[[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
[self value.
Processor terminateActive] in BlockClosure>>newProcess

Closing WebSocket(127.0.0.1:33022)
New WebSocket(127.0.0.1:33024)
WebSocket(127.0.0.1:33024)
ConnectionClosed: Connection closed while waiting for data.
[ConnectionClosed signal: 'Connection closed while waiting for data.'] in Socket>>waitForDataFor:
Socket>>waitForDataFor:ifClosed:ifTimedOut:
Socket>>waitForDataFor:
Socket>>receiveDataSignallingTimeout:into:startingAt:
SocketStream>>receiveData
SocketStream>>next
WebSocket>>readMessage
[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil] in [[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil]
on: Error
do: [:ex | self handleError: ex]] in WebSocket>>run
BlockClosure>>on:do:
[[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil]
on: Error
do: [:ex | self handleError: ex]] in WebSocket>>run
BlockClosure>>ensure:
WebSocket>>run
[:req | 
| ws |
ws := req asWebSocket.
ws timeout: 300.
Transcript cr; show: 'New ' , ws.
ws
onMessage: [:data | mutex
critical: [sockets
do: [:s | s send: data]]].
ws
onClose: [Transcript cr; show: 'Closing ' , ws.
mutex
critical: [sockets
remove: ws
ifAbsent: []]].
ws
onError: [:ex | 
Transcript cr; show: ws.
Transcript cr; show: ex description.
Transcript cr; show: ex signalerContext longStack].
mutex
critical: [sockets add: ws].
ws run] in WebSocket class>>example
WebServer>>invokeAction:request:
[self
invokeAction: (action at: 2)
request: request] in WebServer>>dispatchRequest:url:
BlockClosure>>on:do:
WebServer>>dispatchRequest:url:
WebServer>>dispatchRequest:
[| ssl |
certName
ifNil: [stream := SocketStream on: aSocket]
ifNotNil: [ssl := Smalltalk
at: #SqueakSSL
ifAbsent: [self error: 'SqueakSSL not installed'].
stream := ssl secureSocketStream on: aSocket.
[stream sslAccept: certName]
on: Error
do: [^ stream destroy]].
[aSocket isConnected]
whileTrue: [stream peek
ifNil: [^ aSocket destroy].
request := self newRequest.
[request readFrom: stream]
on: Error
do: [:ex | 
(ex isKindOf: NetworkError)
ifFalse: [[request send400Response]
on: Error
do: [:ignore | nil]].
^ aSocket destroy].
self dispatchRequest: request].
nil] in WebServer>>handleConnectionFrom:
BlockClosure>>on:do:
WebServer>>handleConnectionFrom:
[self handleConnectionFrom: aSocket] in [[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]] in [[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
BlockClosure>>on:do:
[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]] in [[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
BlockClosure>>ensure:
[[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
[self value.
Processor terminateActive] in BlockClosure>>newProcess

Closing WebSocket(127.0.0.1:33024)
listener terminating, socket: waitingForConnection
listener starting (interface: * port: 8080)The method SmalltalkImage platformName has been deprecated.
Use Smalltalk os platformName

New WebSocket(127.0.0.1:33026)
WebSocket(127.0.0.1:33026)
ConnectionClosed: Connection closed while waiting for data.
[ConnectionClosed signal: 'Connection closed while waiting for data.'] in Socket>>waitForDataFor:
Socket>>waitForDataFor:ifClosed:ifTimedOut:
Socket>>waitForDataFor:
Socket>>receiveDataSignallingTimeout:into:startingAt:
SocketStream>>receiveData
SocketStream>>next
WebSocket>>readMessage
[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil] in [[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil]
on: Error
do: [:ex | self handleError: ex]] in WebSocket>>run
BlockClosure>>on:do:
[[[stream isConnected]
whileTrue: [self readMessage.
frameType = 255
ifTrue: [stream close.
^ self].
self handleMessage: frameData type: frameType].
nil]
on: Error
do: [:ex | self handleError: ex]] in WebSocket>>run
BlockClosure>>ensure:
WebSocket>>run
[:req | 
| ws |
ws := req asWebSocket.
ws timeout: 300.
Transcript cr; show: 'New ' , ws.
ws
onMessage: [:data | mutex
critical: [sockets
do: [:s | s send: data]]].
ws
onClose: [Transcript cr; show: 'Closing ' , ws.
mutex
critical: [sockets
remove: ws
ifAbsent: []]].
ws
onError: [:ex | 
Transcript cr; show: ws.
Transcript cr; show: ex description.
Transcript cr; show: ex signalerContext longStack].
mutex
critical: [sockets add: ws].
ws run] in WebSocket class>>example
WebServer>>invokeAction:request:
[self
invokeAction: (action at: 2)
request: request] in WebServer>>dispatchRequest:url:
BlockClosure>>on:do:
WebServer>>dispatchRequest:url:
WebServer>>dispatchRequest:
[| ssl |
certName
ifNil: [stream := SocketStream on: aSocket]
ifNotNil: [ssl := Smalltalk
at: #SqueakSSL
ifAbsent: [self error: 'SqueakSSL not installed'].
stream := ssl secureSocketStream on: aSocket.
[stream sslAccept: certName]
on: Error
do: [^ stream destroy]].
[aSocket isConnected]
whileTrue: [stream peek
ifNil: [^ aSocket destroy].
request := self newRequest.
[request readFrom: stream]
on: Error
do: [:ex | 
(ex isKindOf: NetworkError)
ifFalse: [[request send400Response]
on: Error
do: [:ignore | nil]].
^ aSocket destroy].
self dispatchRequest: request].
nil] in WebServer>>handleConnectionFrom:
BlockClosure>>on:do:
WebServer>>handleConnectionFrom:
[self handleConnectionFrom: aSocket] in [[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]] in [[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
BlockClosure>>on:do:
[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]] in [[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
BlockClosure>>ensure:
[[[self handleConnectionFrom: aSocket]
on: Error
do: [:ex | aSocket destroy].
mutex
critical: [connections
remove: Processor activeProcess
ifAbsent: []]]
ensure: [aSocket destroy]] in WebServer>>asyncHandleConnectionFrom:
[self value.
Processor terminateActive] in BlockClosure>>newProcess

Closing WebSocket(127.0.0.1:33026)

Any idea what's going on?

Thanks!

--
Bernat Romagosa.