01: /*
02: * TracesSocket.java
03: *
04: * Created on July 3, 2003, 2:59 PM
05: */
06: package tools.tracesviewer;
07:
08: import java.net.*;
09: import java.io.*;
10:
11: /**
12: *
13: * @author deruelle
14: */
15: public class TracesSocket extends Thread {
16:
17: private String fileName;
18: private String port;
19: private InputStream is;
20: private FileWriter fw;
21:
22: /** Creates a new instance of TracesSocket */
23: public TracesSocket(String fileName, String port) throws Exception {
24: this .fileName = fileName;
25:
26: this .port = port;
27:
28: System.out.println("Waiting for a connection on port: " + port);
29: ServerSocket serverSocket = new ServerSocket(Integer.valueOf(
30: port).intValue());
31: Socket newsock = serverSocket.accept();
32: is = newsock.getInputStream();
33: fw = new FileWriter(fileName);
34:
35: }
36:
37: public void run() {
38: try {
39: while (true) {
40: int i = is.read();
41: fw.write(i);
42: //System.out.print(i);
43: }
44: } catch (Exception e) {
45: e.printStackTrace();
46: }
47: }
48:
49: }
|