You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TCPServer/TCPServer.class.st
+36-8Lines changed: 36 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,37 @@
1
1
"
2
2
I am most primitive TCP server. I implement classic incoming connections loop. My subclasses should implement #processNewConnection: .
3
3
4
-
I am created by #on: message with port number as argument. Then you should call #start to run listener socket and incoming connections loop.
5
-
I have list of running servers on class side.
6
-
#stop message will close listener socket and terminate incoming connections process.
4
+
To start a server simply create an instance and ask it to #start:
7
5
8
-
I delegate sockets creation to TCPNetworkLibrary implementation. It provides simple hook to set up different socket libraries (like Ocean).
6
+
server := TCPServerSubclass new.
7
+
server start.
8
+
9
+
It will run listener socket and incoming connections loop.
10
+
11
+
By default I allow OS to assign free port for me (using zero port number):
12
+
13
+
server := TCPServerSubclass new.
14
+
server port. ""==> 0""
15
+
server start.
16
+
server port > 0 ""==> true""
17
+
18
+
But users can specify concrete port using #on: message:
19
+
20
+
server := TCPServerSubclass on: 40422
21
+
22
+
If given port is busy the #start message will signal an error.
23
+
24
+
To stop the server use #stop message:
25
+
26
+
server stop.
27
+
28
+
It will close listener socket and terminate incoming connections loop.
29
+
30
+
I maintain the list of all running servers on my class side variable #RunningServers.
31
+
32
+
Implementation details
33
+
34
+
I delegate sockets creation to TCPNetworkLibrary implementation. It provides simple hook to set up different socket libraries (like Ocean) and simplifies testing.
9
35
10
36
Public API and Key Messages
11
37
@@ -19,8 +45,8 @@ Internal Representation and Key Implementation Points.
0 commit comments