Jump to content
xisto Community
Sign in to follow this  

Receiving Data With Winsock

Recommended Posts

I'm making a game server browser that, when loaded, runs through an array of IP's and sends a query to each of them - each of these IP's returns some data. When I receive this data, I want to parse it and store it in to the arrayI'm making a game server browser that holds all the game data in an array which is a custom data structure. The array holds information like IP, number of players, name of server etc.When the program loads, I want it to loop through the servers array and query all the IP's in there (the IP's are pre-set). The game servers will send back some data, which I want to parse and stick back in to the right array value corresponding to the IP (ie information like game server name, number of players etc).What would be the best way to do this? At the moment, when the form loads I've got it looping through the array and sending off the query string, but when it returns, how do I find the right array etc? Would I be best off to just make a function that searches the array for the IP that has been returned, find the matching array value and enter the data in there using that? Or is there a better method?Another problem I have is that the Winsock control will not only be used for handling the return of query data from servers - it may also handle other data such as login information. How would I go about telling the Winsock control what sort of data it should be expecting? What I mean is, if I'm logging in, when data is returned, I want it to validate the user, but if I'm getting server query data back, I want it to parse it or something.thanks,kvarnerexpress

Share this post

Link to post
Share on other sites

What protocol are you using? TCP or UDP?

If you are using UDP protocol, it will make things easier for you, but UDP is a connectionless protocol, meaning, there is no permanent connection made between clien and a server.

If you are using TCP protocol, that will be a bit more difficult. You will need an array of Winsock controls, that will be used for each connection with the client.
FOr example, use one Winsock control to listen for incoming connections, and an array of Winsock controls to accept incoming data for each client.

It would look something like this:

' Create 2 Winsock controls, name one wskListen, and one wskClients' Set Index property of wskClients to 0Private Sub wskListen_ConnectionRequest(ByVal requestID As Long)  If NumConnections = 0 Then    wskClients(0).Accept requestID  Else    Load wskClients(NumConnections)    wskClients(NumConnections).Accept requestID  End If  NumConnections = NumConnections + 1End Sub

This is just an example, there is a lot of example code on Planet Source Code (PSC)

As for recognition of incoming data, you will need to design your own protocol, and make a parser for that. Maybe something like this:

For login data:
LOGIN: <username> <password>

For client incoming data
CLIENT: <data>

This is ofcourse just an idea, off head... If I come up with something better, I'll post it here. Hope I helped.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.