Board index » delphi » Winsock Programming Function Help Needed !

Winsock Programming Function Help Needed !

Hello,

This may be a simple problem or might be complicated I don't yet know.

In the winsock pascal unit there's a function which looks similar to this

  function recv (s : tSOCKET; buf : PChar; len, flags : integer) : integer;

It calls the winsock.dll file so I have know information on what its
actually doing.

My problem is that when i use this function to recieve data, it will wait
for data and then
return it, however if there's no data the program will hang until it
recieves data. This is annoying as if I want to put in any input then i am
unable too.

Can anybody help me ? If it is a simple case of having two windows then can
somone help we work this out in TPW 1.5 using wincrt ?

Thank you

please e-mail a copy of your reply to g.bre...@btinternet.com as I have
limited internet access.

Gary

 

Re:Winsock Programming Function Help Needed !


In article <01bd3a4c$14d0ddc0$a13163c3@btinternet>, "Gary Brewer"

Quote
<g.bre...@btinternet.com> writes:
>In the winsock pascal unit t

Where did you get this winsock unit?

Thanks.
***Andrew Bishop
***AKBis...@usa.net [aol.com, also]
***Veggie Tales Fan
 ___
/     \
| 00 |      _____
|  o  |    /   00   \
|  U |    |     o     |
\     /    \   \_/   /
       

Re:Winsock Programming Function Help Needed !


Quote
"Gary Brewer" <g.bre...@btinternet.com> wrote:
>  function recv (s : tSOCKET; buf : PChar; len, flags : integer) : integer;
>My problem is that when i use this function to recieve data, it will wait
>for data and then
>return it, however if there's no data the program will hang until it
>recieves data. This is annoying as if I want to put in any input then i am
>unable too.

You need to set the socket non-blocking, from some of my code :
 flag := 1 ;
 err := ioctlsocket (path, FIONBIO, flag) ;  { make non-blocking }

This should be done before connecting. Flag is a longint, path is
the socket path, and FIONBIO is defined as :
  IOCPARM_MASK = $7F ;
  IOC_IN = $80000000 ;
  FIONBIO = IOC_IN or ((longint(sizeof(longint)) and IOCPARM_MASK) shl
              16) or (longint(byte('f')) shl 8) or 126 ;

Now, if you do a recv and there is nothing there you should get
the error EWOULDBLOCK, defined as :
  WSABASEERR = 10000 ;
  EWOULDBLOCK = WSABASEERR + 35 ;

Other Threads