Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Mar : Re: winosck.send not working correctly ?

www.cryer.info
Managed Newsgroup Archive

Re: winosck.send not working correctly ?

Subject:Re: winosck.send not working correctly ?
Posted by:"INT3" (int0..@gmail.com)
Date:Wed, 22 Mar 2006 14:09:15

Hi

I have tried your code and same result.
maybe the server has flood protection and does not accept commands too
quickly.
thank you


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:44163628$1@newsgroups.borland.com...
>
> "INT3" <INT0x3@gmail.com> wrote in message
> news:441501e3$1@newsgroups.borland.com...
>
> > but it seems i am sending data to the server too quickly
>
> That is highly unlikely.  Speed has nothing to do with TCP/IP's ability to
> deliver data to the other party.
>
> > i am only receiving the extra information from the last user in the
list.
>
> Then you are likely writing your data to the socket incorrectly, or
reading
> from the socket incorrect.  Please show your actual code.  Are you taking
> into account that because you are using a non-blocking socket, you are
> responsible for detecting and managing incomplete packets yourself?
>
> > if i use sleep(50) after the SendText procedure it works ok,
> > if i use sleep(40) i receive information from some users.
>
> That suggests to me that you are not looking at the return value of
> SendText(), and are thus not taking into account situations where
SendText()
> cannot send the full string in a single packet of data.  Partial data
> packets are VERY common in non-blocking socket programming.  You must
detect
> them so that you can resend pending data that could not be sent right
away.
>
> > i am using this code to send data to the server.
>
> That code is not using WSAGetLastError() to find out why send() failed.
If
> send() returns SOCKET_ERROR and WSAGetLastError() then return
> WSAEWOULDBLOCK, an error did NOT actually occur.  The data simply could
not
> be accepted by the socket without blocking the calling thread (which
> obviously is an illegal operation for a non-blocking socket), so the
socket
> tells the calling thread as much so that it can try to resend the unsent
> data again later.
>
> Try this code instead;
>
>     function TTCPSocket.SendBufferTo(Socket: TSocket; Buffer: PChar;
> BufLength: Integer): Integer;
>     begin
>         Result := 0;
>         if (Socket <> INVALID_SOCKET) and (BufLength > 0) then
>         begin
>             Result := WinSock.Send(Socket, Buffer^, BufLength, 0);
>             if (Result = SOCKET_ERROR) and
>                 (WSAGetLastError <> WSAEWOULDBLOCK) and
>                 Assigned(FOnError) then FOnError(Self, WSAGetLastError);
>         end;
>     end;
>
>     function TTCPSocket.SendText(const s: string): Boolean;
>     var
>         temp: String;
>         sent: Integer;
>     begin
>         Result := False;
>         temp = s;
>         while temp <> '' do
>         begin
>             sent = SendBufferTo(FSocket, PChar(temp), Length(temp));
>             if sent = SOCKET_ERROR then
>             begin
>                 if WSAGetLastError = WSAEWOULDBLOCK) then Continue;
>                 Exit;
>             end;
>             if sent = 0 then Exit;
>             if sent = Length(temp) then Break;
>             temp = Copy(temp, sent+1, MaxInt);
>         end;
>         Result := True;
>     end;
>
>
> Or this:
>
>     function TTCPSocket.SendBufferTo(Socket: TSocket; Buffer: PChar;
> BufLength: Integer): Boolean;
>     var
>         sent: Integer;
>     begin
>         Result := False;
>         if Socket <> INVALID_SOCKET then
>         begin
>             while BufLength > 0 do
>             begin
>                 sent := WinSock.Send(Socket, Buffer^, BufLength, 0);
>                 if sent = SOCKET_ERROR then
>                 begin
>                     if WSAGetLastError = WSAEWOULDBLOCK then
>                     begin
>                         Sleep(10);
>                         Continue;
>                     end;
>                     if Assigned(FOnError) then FOnError(Self,
> WSAGetLastError);
>                     Exit;
>                 end;
>                 if Sent = 0 then Exit;
>                 Inc(Buffer, sent);
>                 Dec(BufLength, sent);
>             end;
>             Result := True;
>         end;
>     end;
>
>     function TTCPSocket.SendText(const s: string): Boolean;
>     begin
>         Result := SendBufferTo(FSocket, PChar(s), Length(s));
>     end;
>
>
> Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive