blob: 7a65290dcc81dc2b7d35d61e6e2d1a9de6084fe0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package scala.tools.util
import java.net._
import java.io._
abstract class SocketServer {
def shutDown: boolean
def session(): unit
var out: PrintWriter = _
var in: BufferedReader = _
val port: int = try {
val s = new ServerSocket(0)
val p = s.getLocalPort()
s.close()
p
} catch {
case e: IOException =>
System.err.println("Could not listen on any port; exiting.")
exit(1)
}
def run(): unit = {
while (!shutDown) {
val serverSocket = try {
new ServerSocket(port)
} catch {
case e: IOException =>
System.err.println("Could not listen on port: "+port+"; exiting.")
exit(1)
}
val clientSocket = try {
serverSocket.accept()
} catch {
case e: IOException =>
System.err.println("Accept on port "+port+" failed; exiting.")
exit(1)
}
out = new PrintWriter(clientSocket.getOutputStream(), true)
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()))
session()
out.close()
in.close()
clientSocket.close()
serverSocket.close()
}
}
}
|