NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Analyzer.Monitor.Client.TextRequest Class Reference
Inheritance diagram for Ntp.Analyzer.Monitor.Client.TextRequest:
Collaboration diagram for Ntp.Analyzer.Monitor.Client.TextRequest:

Public Member Functions

 TextRequest (IPAddress ip, int port)
 
 TextRequest (IPEndPoint server)
 
string Send (string command)
 
- Public Member Functions inherited from Ntp.Analyzer.Monitor.Client.Request
override string ToString ()
 

Private Attributes

StringBuilder result
 

Additional Inherited Members

- Protected Member Functions inherited from Ntp.Analyzer.Monitor.Client.Request
 Request (IPAddress ip, int port)
 
 Request (IPEndPoint server)
 
- Properties inherited from Ntp.Analyzer.Monitor.Client.Request
IPEndPoint Server [get]
 

Detailed Description

Definition at line 31 of file TextRequest.cs.

Constructor & Destructor Documentation

Ntp.Analyzer.Monitor.Client.TextRequest.TextRequest ( IPAddress  ip,
int  port 
)
inline

Definition at line 33 of file TextRequest.cs.

34  : base(ip, port)
35  {
36  }
Ntp.Analyzer.Monitor.Client.TextRequest.TextRequest ( IPEndPoint  server)
inline

Definition at line 38 of file TextRequest.cs.

39  : base(server)
40  {
41  }

Member Function Documentation

string Ntp.Analyzer.Monitor.Client.TextRequest.Send ( string  command)
inline

Implements Ntp.Common.Process.IRequest.

Definition at line 45 of file TextRequest.cs.

46  {
47  var clientSocket = new Socket(
48  AddressFamily.InterNetwork,
49  SocketType.Stream,
50  ProtocolType.Tcp);
51 
52  try
53  {
54  IAsyncResult conRes = clientSocket.BeginConnect(Server, null, null);
55  bool success = conRes.AsyncWaitHandle.WaitOne(3000, true);
56 
57  if (!success)
58  {
59  throw new ApplicationException("Failed to connect to server.");
60  }
61 
62  byte[] sendBuffer = Encoding.UTF8.GetBytes(command);
63 
64  SocketError error;
65  clientSocket.Send(sendBuffer, 0, sendBuffer.Length, SocketFlags.None, out error);
66 
67  const int size = 4096;
68 
69  result = new StringBuilder(4096);
70  var buffer = new byte[size];
71 
72  int length;
73 
74  do
75  {
76  length = clientSocket.Receive(buffer, 0, size, SocketFlags.None, out error);
77  string response = Encoding.ASCII.GetString(buffer);
78  response = response.Substring(0, length);
79  result.Append(response);
80  } while (length > 0);
81 
82  return result.ToString();
83  }
84  catch (Exception ex)
85  {
86  Debug.WriteLine(ex.Message);
87  return "Failed to connect to server.";
88  }
89  finally
90  {
91  if (clientSocket.IsBound)
92  clientSocket.Shutdown(SocketShutdown.Both);
93 
94  clientSocket.Close();
95  }
96  }

Member Data Documentation

StringBuilder Ntp.Analyzer.Monitor.Client.TextRequest.result
private

Definition at line 43 of file TextRequest.cs.


The documentation for this class was generated from the following file: