/// <summary>
/// Sends a request to the server
/// </summary>
public ResponseBase SendRequest(RequestBase request) {
//manage the connection state automatically if needed
if (AutoConnect) { Open(); }
//attempt to perform the request
try {
//perform normal checking
if (!Connected) {
throw new ConnectionNotOpenedException("Connection isn't open yet!");
}
//send the header first
_writer.Write(request.GetHeader());
_writer.Flush();
//then the rest of the content
_writer.Write(request.GetBody());
_writer.Flush();
//next, read for the response
return request.OnResponse(_buffer);
}
//forward the exception onto the caller
catch (Exception up) {
//attempt to kill the connection
//ignore any problems since we are
//already forwarding an exception
try { Dispose(); }
catch { }
//and then forward the error for handling
throw;
}
}