flat assembler
Message board for the users of flat assembler.
Index
> Windows > Winsock - blocking question |
Author |
|
vid 15 Jul 2007, 08:19
which API do you use for recieving data in client?
|
|||
15 Jul 2007, 08:19 |
|
Furby 15 Jul 2007, 08:33
somebody deleted someones post and i couldn't reply... so
read this http://beej.us/guide/bgnet/ its in C but you should get the information you want. |
|||
15 Jul 2007, 08:33 |
|
ManOfSteel 16 Jul 2007, 08:09
@vid: I'm using the usual recv, why? Is there any other way to do it?
@Furby: thanks for the link, but I already have these in Microsoft's Winsock API reference .hlp file. |
|||
16 Jul 2007, 08:09 |
|
vid 16 Jul 2007, 10:34
ManOfSteel: you can use overlapped file I/O to read socket, or you can perform reading in separate thread, or you can use select() to see which handles contain some data to read.
|
|||
16 Jul 2007, 10:34 |
|
Nikolay Petrov 17 Jul 2007, 20:35
|
|||
17 Jul 2007, 20:35 |
|
ManOfSteel 19 Jul 2007, 14:34
Hello,
@vid: I'm sorry for not replying earlier, I've been quite busy lately. Even if you use threads, you should still use recv, don't you? In fact, I've already tried using threads but something seemed wrong: the thread terminated before it had finished its work. I had to add a sleep API to slow it down. Is there any better way to do it? Code: invoke CreateThread,0,0,RecvProc,0,0,Temp invoke CloseHandle,eax invoke Sleep,5000 jmp finish ... finish: invoke closesocket,[hSocket] invoke WSACleanup ... proc RecvProc invoke recv,[hSocket],Buffer,10,0 or eax,eax jz disconnected cmp eax,-1 jne success invoke MessageBox,0,'No response from server','Client',0 jmp finish endp I usually don't use threads much, so please bear with me. Also, what about select? I've read about it, but didn't understand much. Could you give me some pseudo-code instructions on how to use it? @Nikolay Petrov: thanks for the link. It seems interesting, I've downloaded everything. |
|||
19 Jul 2007, 14:34 |
|
Gizmo 19 Jul 2007, 22:06
to use nonblocking berkely sockets you must use the select function to see if there is data to recv() yet and then recv() it if it says there is
in c this is Code: //defines typedef struct timeval { long tv_sec; long tv_usec; } timeval; typedef struct fd_set { u_int fd_count; SOCKET fd_array[FD_SETSIZE]; } fd_set; int select( int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout ); //how to use it timeval ReadWait; ReadWait.tv_sec=0; ReadWait.tv_usec=0; //no wait and no blocking fd_set ReadSet; ReadSet.fd_count=1; ReadSet.fd_array[0]=ReadSocket; //socket(s) to listen to if(select(0,&ReadSet,NULL,NULL,&ReadWait)>0) { recv(ReadSocket,buffer, len,0); } |
|||
19 Jul 2007, 22:06 |
|
ManOfSteel 20 Jul 2007, 18:43
@Gizmo:
Thank you. I tried it, but it seems to work only when I set tv_sec to at least 1 second. By the way, 1)when tv_usec is used, is it added to tv_sec? 2)Also, what's the purpose of having microsecond-precision network operations? |
|||
20 Jul 2007, 18:43 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.