I have a single connections socket server that I am working on that behaves
strangely.
When I attempt to connect, sometimes I get and error 104 on both ends. The
connection is established and immediately dropped. Once the connections begin
to fail, I can never reconnect unless I restart the application. I get the same
result if I am using the client that I wrote in synapse or if I connect using
telnet.
Another odd thing is that when the connection fails, the handle that is
returned by Accept is either 160 or 162. I thought this was rather strange.
I am running this under Ubuntu 8.10 AMD64.
Here is the code.
procedure TMySocketServer.Execute;
var
MySocket: TTCPBlockSocket;
Bound: boolean;
Cnn: THandle;
Client: TBlockSocket;
s: string;
lasterr: integer;
lasterrdesc: string;
listencounter: integer;
begin
prvConnected := false;
MySocket := nil;
while not self.Terminated do
begin
if not prvConnected then
begin
Bound := false;
while not Bound do
begin
sleep(500);
if MySocket <> nil then
begin
MySocket.CloseSocket;
MySocket.Free;
end;
MySocket := TTCPBlockSocket.Create;
MySocket.ResetLastError;
MySocket.Bind('127.0.0.1','50001');
MySocket.SetLinger(true,100);
Bound := MySocket.LastError = 0;
end;
listencounter := 0;
writeln('Bind succeeded');
MySocket.ResetLastError;
MySocket.Listen;
lasterr := MySocket.LastError;
lasterrdesc := MySocket.LastErrorDesc;
writeln('Listen result: ' + 'Error - ' + inttostr(lasterr) + ': ' +
lasterrdesc);
repeat
if Terminated then
break;
MySocket.ResetLastError;
if MySocket.CanRead(100) then
begin
MySocket.ResetLastError;
Cnn := MySocket.Accept;
lasterr := MySocket.LastError;
writeln('Got connection. Handle - ' + inttostr(Cnn) + ', Error - ' +
inttostr(lasterr));
if lastErr = 0 then
begin
prvConnected := true;
Client := TTCPBlockSocket.create;
Client.SetLinger(true,100);
Client.ResetLastError;
Client.Socket := cnn;
lasterr := Client.LastError;
writeln('Client Handle - ' + inttostr(Client.Socket) + ', Error -
' + inttostr(lasterr));
// Client.SendString('Connect'#13#10);
ClearLists;
end;
inc(listencounter);
end;
until prvConnected or (listencounter > 50);
end
else
begin
Client.ResetLastError;
s := Client.RecvString(1);
lasterr := Client.LastError;
lasterrdesc := Client.LastErrorDesc;
if lasterr <> 0 then
if lasterr <> 110 then
begin
Client.CloseSocket;
Client.Free;
Client := nil;
prvConnected := false;
writeln('closed socket:' + inttostr(lasterr) + ': ' + lasterrdesc);
end;
end;
//Do something with the data, write to the socket, etc
end;
end;
Any thoughts would be greatly appreciated.
Eddy
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public