SocketTools .NET Edition

HttpServer.SendResponse Method (Int32, MemoryStream)

Send a result code and message to the client in response to a command.

[Visual Basic]
Overloads Public Function SendResponse( _
   ByVal resultCode As Integer, _
   ByVal memStream As MemoryStream _
) As Boolean
[C#]
public bool SendResponse(
   int resultCode,
   MemoryStream memStream
);

Parameters

resultCode
An integer value that specifies the command result code to be returned to the client.
memStream
A MemoryStream object that contains data that should be returned to the client in response to a request.

Return Value

A boolean value which specifies if the response was sent to the client. A return value of true specifies that the operation was successful. If an error occurs, the method returns false and the application should check the value of the LastError property to determine the cause of the failure.

Remarks

The SendResponse method is used to respond to a command issued by the client from within an OnCommand event handler. Command responses are normally handled by the server as a normal part of processing a command and this method is only used if the application has implemented custom commands or wishes to modify the standard responses sent by the server.

Result codes must be three digits (in the range of 100 through 999) and although this method will support the use of non-standard result codes, it is recommended that the client application use the standard codes defined in RFC 2616 whenever possible. The use of non-standard result codes may cause problems with HTTP clients that expect specific result codes in response to a particular command.

If you do not wish to return any data to the client in response to its request (for example, if you want the response to only consist of the headers set using the SetHeader method), then you can use the overloaded version of this method that omits the buffer and length parameters, and should specify a result code of 204. This tells the client that the request was successful and there is no data included with the response.

This method should only be called once in response to a command sent by the client. If a result code has already been sent in response to a command and this method is called, it will fail and return an error. This is necessary because sending multiple result codes in response to a single command may cause unpredictable behavior by the client.

This version of the method would typically be used when returning binary data to the client. For textual data, such as an HTML or XML response, it is recommended that you use the overloaded version of this method that accepts a string.

See Also