1
2
3
4
5
6 namespace System
7 {
8 public class LogClient
9 {
10 static LogClient() : instance(new LogClient())
11 {
12 }
13 private LogClient() : port(55000), connected(false), socket(null)
14 {
15 }
16 public static LogClient& Instance()
17 {
18 return *instance;
19 }
20 public nothrow void SetPort(int port_)
21 {
22 port = port_;
23 }
24 public nothrow int Port() const
25 {
26 return port;
27 }
28 public nothrow bool Connected() const
29 {
30 return connected;
31 }
32 public void Connect()
33 {
34 connected = true;
35 socket.Reset(new Socket("127.0.0.1", ToString(port)));
36 }
37 public void CloseConnection()
38 {
39 connected = false;
40 socket.Reset();
41 }
42 public void Write(const string& str)
43 {
44 if (!connected)
45 {
46 Connect();
47 }
48 socket->Write(str);
49 }
50 private static UniquePtr<LogClient> instance;
51 private int port;
52 private bool connected;
53 private UniquePtr<Socket> socket;
54 }
55 }