1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jdiagnose.library;
17
18 import org.jdiagnose.DiagnosticUnit;
19
20 import java.io.IOException;
21 import java.net.Socket;
22 import java.net.UnknownHostException;
23
24 /***
25 * Tries to open a Tcp Port and then closes it. This Diagnostic
26 * can be used to check connectivity to a particular host and
27 * port.
28 *
29 * @author jamie
30 */
31 public class TcpDiagnostic extends DiagnosticUnit {
32
33 private String host = "";
34 private int port = 80;
35
36 public TcpDiagnostic() {
37
38 }
39
40 /***
41 * Create a new DiagnosticUnit with a Fully Qualified Name
42 *
43 * @param name the name of this diagnostic.
44 */
45 public TcpDiagnostic(String name, String host, int port) {
46 super(name);
47 this.host = host;
48 this.port = port;
49 }
50
51 public TcpDiagnostic(String host, int port) {
52 this.host = host;
53 this.port = port;
54 }
55
56 public void diagnoseConnection() throws UnknownHostException, IOException {
57 Socket socket = new Socket(host, port);
58 socket.close();
59 }
60 /***
61 * @return Returns the host.
62 */
63 public String getHost() {
64 return host;
65 }
66 /***
67 * @param host The host to set.
68 */
69 public void setHost(String host) {
70 this.host = host;
71 }
72 /***
73 * @return Returns the port.
74 */
75 public int getPort() {
76 return port;
77 }
78 /***
79 * @param port The port to set.
80 */
81 public void setPort(int port) {
82 this.port = port;
83 }
84 }