The ADS.Server class is the only class in the ADS library. It is used to manage servers of four different types, defined by the ADS.ServerType enum:

  • HTTP
  • HTTPS
  • Data
  • Custom

 

HTTP and HTTPS servers

A HTTP or HTTPS server is used to create a web server for viewing in a web browser. A HttpListenerRequest object is passed to the callback, and the server expects a string containing the response in return.

Data Servers

A data server is used to make a low-level version of HTTP. A string that was sent by the client is passed to the callback, and the server expects a string containing the reply in return. The connection is then closed.

Custom Servers

A custom server can be used to make any type of server. A Socket object is passed to the callback. No return value is necessary. (However, you must still return null, otherwise you code will not compile. The return value is merely ignored by the library.)

Example

 

public void UseServerClass()
{
	Server server = new Server(new IPEndPoint(0, 80), ServerType.HTTP, Callback);
	Console.Write("Server successfully started.");
}
object Callback(object request)
{
	HttpListenerRequest req = (HttpListenerRequesr)request;
	string response =
@"<html>
<head>
<title>Automated Response</title>
</head>
<body>
<p>This is an automated response. Your request was: " + req.Url + @"</p>
<p>Recieved at: <b>" + DateTime.Now().ToString() + @"</b></p>
</body>
</html";
	return response;
}

Last edited Jun 21, 2012 at 6:08 PM by nmertin, version 7

Comments

No comments yet.