1 //////////////////////////////////////////////////////////////////////////////
2 // dexterIM - Instant Messaging Framework
3 // Copyright (C) 2003 Christoph Walcher
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 }