1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.microemu.cldc.socket;
22
23 import java.io.IOException;
24 import java.net.InetAddress;
25 import java.net.ServerSocket;
26
27 import javax.microedition.io.StreamConnection;
28
29 public class ServerSocketConnection implements
30 javax.microedition.io.ServerSocketConnection {
31
32 private ServerSocket serverSocket;
33
34 public ServerSocketConnection(int port) throws IOException {
35 serverSocket = new ServerSocket(port);
36 }
37
38 public String getLocalAddress() throws IOException {
39 InetAddress localHost = InetAddress.getLocalHost();
40 return localHost.getHostAddress();
41 }
42
43 public int getLocalPort() throws IOException {
44 return serverSocket.getLocalPort();
45 }
46
47 public StreamConnection acceptAndOpen() throws IOException {
48 return new SocketConnection(serverSocket.accept());
49 }
50
51 public void close() throws IOException {
52 serverSocket.close();
53 }
54
55 }