flat assembler
Message board for the users of flat assembler.

Index > Windows > Winsock question

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Suppose I want to write an IRC client in FASM with Winsock. I know I would get the IRC RFC, connect to a IRC server and send the commands following the RFC.

But how would I know when the server is sendind data? Is there a way to have an event-based handling of data? Like when the socket is ready to be read I read, and when it's ready to be written I write?

I hope you understand my question.

Thanks Razz
Post 09 Sep 2008, 21:25
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
http://board.flatassembler.net/topic.php?t=9191 Quetannon itself answers that question but there are more non-blocking methods actually. Considering that you want to write a client I think that Quetannon's way is enough for you application though.

Follow all links there.
Post 09 Sep 2008, 22:40
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Personally I'm a fan of WSAEventSelect - it scales pretty well if done right (torrent client with thousands of connections and still not too much CPU overhead), it's not overly complicated, and if you want anything but a REALLY simple IRC cilent, you will need multiple connections anyway (multi-server, DCC, ...)

The trick with WSAEventSelect is to create N events, and have an array of N linked lists (or whatever) with connection information. You can then use WaitForMultipleObjectSex to wait for one of those N events, a termination event (keep N one below MAXIMUM_WAIT_OBJECTS), or a timeout.

If you get between WAIT_OBJECT_0 and WAIT_OBJECT_0+N-1, you traverse the corresponding array-entry list and process all the list entries, calling WSAEnumNetworkEvents on the network socket to determine if the socket has activity. It might seem wasteful polling all sockets in the list for activity, but remember you only get an event when at least one socket has data, and you're partitioning your sockets into N lists. It works well in practice, is somewhat less work than a full IOCP implementation, and iirc also works on Win9x which IOCP doesn't.
Post 09 Sep 2008, 23:21
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I've read the Quetannon example and still couldn't understand WSAAsyncSelect, but when I read this tutorial http://johnnie.jerrata.com/winsocktutorial/ everything was clear.

And now I understand the Quetannon example.

WSAAsyncSelect seems to be very handy. I still need to write my own code and test it. But it looks like what I was looking for.

Thanks guys.
Post 16 Sep 2008, 23:56
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.