News  [SoftwareSite

Latest News
Older News
RSS Feed
 
Complete Projects
Useful Classes
Top Downloads
Message Board
AllAPI.net
 
Send Comments
Software License
Mentalis.org Buttons
Donate
 
Forums -> Security Library Forum
 
Last "lRCode = mSocket.Receive(lReceiveBuffer);" is slow.  
by Mike VanZant [mvanzant at gatewaysystems dot com]
posted on 2004/07/23

I am using the SecureSocket class and am processing the Receive() in a loop until the return value is zero.

The application is designed to automatically navigate a HTTPS web site to eventually retrieve a data file.

The problem is that the call to (in a loop):

value = socket.Receive(buffer);

is fast until the final call returning a value of zero. On some web sites this can take 15 seconds or more.

On other web sites, all of the calls are fast.

I don't understand why this is happening and would appreciate anyone's insight into how I can fix this. Maybe some setting? Thanks!

Below are the relevant functions of the source code I'm using:

private void Connect(){
this.TryCallBackProgress(0, 0);
IPHostEntry lResolvedServer;
IPEndPoint lServerEndPoint;
SecureProtocol sp;
try{
AppLog.Log.DebugMessage("mServerName: " + mServerName);
lResolvedServer = Dns.Resolve(mServerName);
foreach( IPAddress addr in lResolvedServer.AddressList){
AppLog.Log.DebugMessage("IP: " + addr.ToString());
lServerEndPoint = new IPEndPoint(addr, this.URL.Port);
if(mIsHTTPS){
sp = SecureProtocol.Ssl3|SecureProtocol.Tls1;
}else{
sp = SecureProtocol.None;
}
SecurityOptions options = new SecurityOptions(sp);
options.Certificate = null;
options.Entity = ConnectionEnd.Client;
options.CommonName = this.URL.Host;
options.VerificationType = CredentialVerification.AutoWithoutCName;
options.Flags = SecurityFlags.Default;
options.AllowedAlgorithms = SslAlgorithms.ALL; //SslAlgorithms.SECURE_CIPHERS;
mSocket = new SecureSocket(addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp, options);
try{
mSocket.Connect(lServerEndPoint);
AppLog.Log.DebugMessage("Connected socket.");
}
catch(Exception e){
AppLog.Log.Error("Connection of socket failed.", e);
//Connect failed so try the next one.
//Make sure to close the socket we opened.
if(mSocket != null){
mSocket.Close();
}
continue;
}
break;
}
}catch(Exception e){
AppLog.Log.Error("Client connection failed.",e);
throw;
}
}


private void ReceiveData(){
mContentLengthBytesForCallBack = 0;
mContentStartByte = 0;
this.TryCallBackProgress(this.mContentLengthBytesForCallBack, 0);
StringBuilder sbDataReceived = new StringBuilder();
byte[] lReceiveBuffer;
int lRCode;
string lstr = "";
int lTotalBytesReceived = 0;
this.mContentLength = 0;
try{
while(true){
lReceiveBuffer = new byte[16384]; //byte[102400]; //byte[10240]; //byte[1024];
try{
this.TimingLog("Doing socket receive with buffer size " + lReceiveBuffer.Length.ToString() + "...");
lRCode = mSocket.Receive(lReceiveBuffer);
this.TimingLog("Finished socket receive with return code of " + lRCode.ToString() + ".");
lTotalBytesReceived += lRCode;
if(lRCode > 0){
lstr = Encoding.ASCII.GetString(lReceiveBuffer,0,lReceiveBuffer.Length);
sbDataReceived.Append(lstr);
this.ParsePartialResponseForCallBackProgress(sbDataReceived.ToString());
}
else if(lRCode == 0){
break;
}
else{
Log.DebugMessage("socket receive returned negative code: " + lRCode);
break;
}
}
catch(ObjectDisposedException e){
Log.Error("Socket was closed.", e);
break;
}
catch(SocketException e){
Log.Error("SocketException", e);
break;
}
}
}
catch(Exception e){
Log.Error("Receive Failed.", e);
throw;
}
finally{
this.ParseReply(sbDataReceived.ToString());
}
}

by Mike VanZant [mvanzant at gatewaysystems dot com]
posted on 2004/07/23

I found that the problem is avoided if I send the HTTP Header as:

GET /whatever/abc HTTP/1.0

instead of

GET /whatever/abc HTTP/1.1

I don't know why this would affect the last:

value = socket.Receive(buffer);

(looping until value = 0)

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2004/08/05

HTTP/1.1 servers keep their connection open for a while to allow for new incoming HTTP requests over the same channel. That's why you're seeing a 15 second delay with HTTP/1.1. HTTP/1.0 doesn't support this feature.

 

Copyright © 2002-2007, The Mentalis.org Team. All rights reserved.
This site is located at http://www.mentalis.org/
Send comments to the webmaster.