Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / iCON: Winsock Programming with DB

Author
Message
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 31st Dec 2007 09:43 Edited at: 12th Jan 2008 15:36
Inspired by Benjamin Wharton's Winsock, Multisync, and Tempest Network Libraries, I set off on a adventure to learn more about Winsock in DBP and create my own TCP/UDP Network Lib with Winsock in DB. In this sub-project I'm getting exposed to DLLs, advance DBP features like Pointers, and the lower inner workings Networking in Windows.

My goal for Inter-Connector (iCon or DarkICon?) is to support both TCP/UDP. I expect to learn and share what I uncover in this project with all interested parties. If all else fails, I will resort Benjamin's excellent Network Libraries.

iCon Network Lib v011208


iCon Server


iCon Client


TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 31st Dec 2007 10:38 Edited at: 3rd Jan 2008 20:07
iCon Server & Client code move into the post above.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 2nd Jan 2008 02:58
IanM and Benjamin, I could sure use your insight on implementing non-blocking sockets Any other insight welcomed as well.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 2nd Jan 2008 12:18 Edited at: 3rd Jan 2008 19:42
Considering you only have one thread to play with, these are the options for non-blocking socket operation:

Non-blocking function calls - You call a function such as recv for instance, and if the call cannot complete immediately (if there is no data to receive) the function will return with the error code set to 10035. This method means you have to check each socket for data all the time.

Poll on select - Set up a list of sockets to be checked for readability/writeability and call select to check for activity on said sockets. Eliminates the need to manually call recv on each socket, but you must set up a list of sockets every time you want to call socket.

Use event objects - Associate each socket with an event object, and then call WSAWaitForMultipleEvents to poll on a list of event objects, similarly to what you do with select. The advantage of this method is that you don't have to set up a list of event objects each time you want to check them for activity. The disadvantage is that you can only poll on 64 event objects per thread.

Use overlapped I/O and completion ports - Queue a series of accept/recv/send operations, and then poll on GetQueuedCompletionStatus to receive indication of operation success/failure. Probably the most efficient method, but also the most difficult to work with.

For simplicity I'd try the first method for now, and move onto event objects when you want better efficiency.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 2nd Jan 2008 13:10
Wow. Theres a lot to learn. Sincere Thanks Benjamin.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 3rd Jan 2008 07:29 Edited at: 3rd Jan 2008 16:26
Dear Network Gurus, any suggestions on how to deal with winsock's pointer to structures like:



in DBP? DBP doesn't support Ptrs to UDTs.

Benjamin I analyzed the Address Structure you created in the Winsock lib and compared it against winsock's sockaddr.






Unfortunately, I stumped as to how you are working magic here.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 3rd Jan 2008 13:43 Edited at: 3rd Jan 2008 13:44
For an fd_set structure just allocate a piece of memory and use pointers like I did with the address structure.



Quote: "Unfortunately, I stumped as to how you are working magic here."

The structure you should be looking at is sockaddr_in.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 3rd Jan 2008 17:46 Edited at: 3rd Jan 2008 17:47
Once Again, Thanks Benjamin, you are indeed a DB Programming Expert. I think I grasp whats going on with Structures. In DB they can be handled in a linear fashion in memory.

For example in the FDset Structure the u_int fd_count is the stored in the first Memory Byte and SOCKET fd_array[FD_SETSIZE] is stored in consecutive bytes in 32 bit increments (because I only need the socket number stored in SOCKET structure).

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 3rd Jan 2008 19:40 Edited at: 3rd Jan 2008 19:44
Quote: "Thanks Benjamin, you are indeed a DB Programming Expert."

You're welcome, and thanks.

Quote: "For example in the FDset Structure the u_int fd_count is the stored in the first Memory Byte"

It's actually 4 bytes (u_int = unsigned integer). The SOCKET type is also an unsigned int, so yes they are stored in 32 bit increments.

By the way, I made a mistake when I said select can only work with 64 sockets at a time, this is just a default limit set when using Winsock in C++.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 7th Jan 2008 09:39
Benjamin,

Whats your opinion on implementing Multicasting?

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 7th Jan 2008 14:45
I've never done it personally, for the single reason that it doesn't work over the internet, only a local area network.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 7th Jan 2008 15:01
Quote: "I've never done it personally, for the single reason that it doesn't work over the internet, only a local area network."
That's unfortunate, it would really be benificial for network games utilizing the internet. Today I will be taking a crack at non-blocking sockets. Truly appreciate your assistance.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 8th Jan 2008 02:29 Edited at: 8th Jan 2008 02:35
I was originally under the impression that Sockets worked like a permanent net connectors in higher level Network Libs (ie Multisync). However, I've come to realization that they work at a much lower-level, and are short-lived net connectors that are constantly set up and tore down at the end of each message. A permanent connection is handled virtually in higher-level libs.

Is my understanding correct?

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Jan 2008 03:33
Fortunately not, that would be rather difficult to handle. Once a socket is connected, data can be sent and received until the socket is closed or until an unrecoverable error occurs.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 12th Jan 2008 15:40 Edited at: 12th Jan 2008 15:42
Benjamin,

I just wanted to let you know that I truly appreciate your expert assistance in this project. I'm learning new things in both DBP and C++, thanks to you. This project is really opening up my eyes to the power many of the features (especially pointers) I have shyed away from. I have been enlightened.

Kudos to Benjamin Wharton.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 13th Jan 2008 02:59
Glad to be of help.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 24th Jan 2008 02:54
Well Benjamin, after some deep thought, I have decided to resume development of my game with Multisync. Its been fun working on iCon and i've learned a great deal with both DBP and C++. However, if I am too stay motivated I must get going on the game, so its time to use whats available. Sincere thanks for all your help.

Login to post a reply

Server time is: 2024-04-26 23:49:59
Your offset time is: 2024-04-26 23:49:59