blob: ae835b0775321c589d097112a36c04dc2d54e425 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*************************************************
*
* = FILENAME
* LoggerTest.java
*
*@author Everett Anderson
*
*************************************************/
package JACE.tests.netsvcs.Logger;
import JACE.SOCK_SAP.*;
import java.io.*;
import java.net.*;
import JACE.OS.*;
import JACE.netsvcs.Logger.*;
/**
*
* This is a simple test log client very similar to the direct_logging
* client of C++ ACE. The logging service should correctly receive
* messages from both the C++ and Java version.
*
* @see JACE.netsvcs.Logger.ServerLoggingAcceptor
*/
public class LoggerTest {
/** Command line: <hostname> [<port>]
*
* Creates a "hello world" log message and sends it to the server logging
* service.
*/
public static void main(String args[])
{
if (args.length != 2) {
System.err.println("Use: LoggerTest <host name> [<port>]");
System.exit(0);
}
ACE.enableDebugging ();
// Set the port
int port = args.length > 1 ?
(new Integer(args[1])).intValue() : ACE.DEFAULT_SERVER_PORT;
SOCKStream cli_stream = new SOCKStream();
INETAddr remote_addr;
String host;
// Try to find the host
try {
host = args[0];
remote_addr = new INETAddr(port, host);
} catch (UnknownHostException uhe) {
ACE.ERROR("UnknownHostException " + uhe);
return;
}
System.out.println("Connecting to " + host + " on port " + port);
SOCKConnector con = new SOCKConnector();
try {
// Connect to the service
con.connect(cli_stream, remote_addr);
} catch (SocketException se) {
ACE.ERROR("Socket Exception " + se);
return;
} catch (IOException ie) {
ACE.ERROR("IOException " + ie);
return;
}
// Send a message with priority 4, the current time,
// and 0 for the process ID.
LogRecord record = new LogRecord(4,
System.currentTimeMillis(),
0);
// Set the text of the message
record.msgData("hello world");
try {
// Send it
record.streamOutTo(cli_stream.socket().getOutputStream ());
// Close the socket
cli_stream.close();
} catch (IOException ie) {
ACE.ERROR("" + ie);
return;
}
}
};
|