1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.ui;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24 import java.net.ServerSocket;
25 import java.net.Socket;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /***
31 * @author christoph
32 * TODO Document
33 */
34 public class TcpTrap {
35
36 private static int welcome[] = new int[] {
37 0x2a, 0x01,
38 0x0c, 0xb6,
39 0x00, 0x04,
40 0x00, 0x00, 0x00, 0x01
41 };
42 private Log log;
43
44 public TcpTrap() {
45 log = LogFactory.getLog(getClass());
46 }
47
48 public void start(int port) {
49 try {
50 ServerSocket server = new ServerSocket(port);
51
52 Socket client = server.accept();
53
54 OutputStream out = client.getOutputStream();
55
56 for (int i=0; i< welcome.length; i++) {
57 out.write(welcome[i]);
58 }
59
60 InputStream in = client.getInputStream();
61
62 int read;
63
64 while ((read = in.read()) != -1) {
65
66 String hex = Integer.toHexString(read);
67
68 if (hex.length() < 2) {
69 hex = "0" + hex;
70 }
71
72 log.debug(hex + " ");
73 }
74 }
75 catch (IOException e) {
76 e.printStackTrace();
77 }
78 }
79
80 public static void main(String[] args) {
81 TcpTrap trap = new TcpTrap();
82 trap.start(5190);
83 }
84 }