• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Somebody PLEASE explain sockets to me and how to use them

X

XirmiX

Guest
I've been told that I'm too inexperienced to deal with networking... fair enough, but right now I think I'm almost confident enough to make a basic connection between clients and a server, aside from one thing, and that being sockets.

I just need to know how I'm supposed to store them on the server, how to make the server recognise when a socket is being sent by the client (I think?) and how to pick a socket from a list of sockets... For async ds_map, is the "socket" key used to store the entire list for sockets, or is it for something else, because I'm not understanding how this makes sense; if you have a bunch of clients, how is one key, "socket", from ds_map async load, supposed to hold all of the info about them? Or is it not supposed to do that, and instead it's supposed to temporarily hold onto the one who's client you're in the process of checking the socket of?

See what I mean, when I say it confuses me? I was previously to not understand sockets and just assume it's magic, which I'm not buying -.- I'm sure I can make at least SOME form of decent connection if somebody would just explain sockets to me. My current code is a work in progress for networking (on the server side for now, I'm also planning to have two seperate projects for Client and Server, so no sharing of objects or files unless they send buffers to each other through packets!):

Server Create event code
Code:
server_trype = network_socket_tcp;
port = 50000;
max_players = 8;
server = network_create_server_raw(server_type, port, max_players);
socket = ds_list_create();
Server Networking event code
Code:
type = async_load[? "type"];

switch(type)
{
    case network_type_connect:
        socket_list = async_load[? "socket"];
        buffer_seek(buffer, buffer_seek_start, 1);
        client_socket_current = buffer_read(buffer, buffer_u8);
        player_username = buffer_read(buffer, buffer_u8);
       
        ds_list_add(socket, client_socket_current);
   
   
    break;
    case network_type_disconnect:
        socket_list = async_load[? "socket"];
       
   
    break;
    case network_type_data:
   
   
    break;
   
}
 

Tsa05

Member
I can't even believe this.
I mean, I spent half an hour writing up a comprehensive list of the basic GML programming methods and techniques that you need to read up on, with examples and descriptions of what everything did, and gave you recommendations for what to work on in order to get ready to do a networked game. I put a lot of effort into that post, and all you could say was "So, what do you guys think I need to teach myself before doing networking? I know it's sockets"

I told you what you need to teach yourself, and it's not sockets. It's data structures. It's what a return statement does. It's how to use a while loop. And the 10 other things in that list. So, you just go right out and make a new topic to say "ok, it's definitely sockets that I need. Explain them?"

How? How can anyone help you?
Sockets are managed entirely by the networking functions. They're stored automatically when created by the networking functions. Want to know how all of the sockets will be held? In a data structure, like I described in my lengthy and thorough post on your other topic. We've been through this. You have not yet spent the time to look into how some of GameMaker's data and programming techniques work. That's why you're "not understanding how this makes sense."

You're chasing more explanation about sockets as though this will clear things up, but it cannot. Sockets, as far as your program is concerned, are a number. GameMaker does not do much with sockets directly. It's a number that's used by the networking functions in order to know which user connection to point at when sending or receiving data. That's it.

You've got to understand that the way these things get stored, and how to know which socket goes to which user is part of your program. It's not some kind of socket secret. You will be storing whatever you need to know about your connections in data structures. You will be storing many socket ids, so that you can send data back through them towards each player. You will be storing other data about the players as well. You'll be checking sockets periodically for connection states and deleting them if there's nobody on the other end. You will be managing the data. The socket is just a number to hang onto for talking to a connected player.

As I mentioned in the other post, what you need to try, in order to make a networked game, is to create a controller object that moves non-player characters around on the screen and keeps track of their info. Once you can do this, it's a short jump to make that controller object talk to the network. And once it talks to the network, the non-player character data can be replaced with data received from a list of sockets. And that's a networked game.
 
G

Guest

Guest
@XirmiX If you ever do get this thing up and running, I think you need to include @Tsa05 in the credits. Maybe some royalties too, quantum meruit.

Edit: And Tsa05, take comfort in the legacy of your work! The posts in this forum probably see 10x their initial use as later google research.
 
G

Guest

Guest
He held back on this, but from now on I'm going to read Tsa05's posts on this topic as if they were in all caps.
 
X

XirmiX

Guest
@Tsa05 once again, sorry, I did not notice a reply over on the other topic. I think I've understood sockets; each client has them and they use them, just like the server does, once connected, to send and receive data from the server. Kind of like an additional plug for the sending and receiving of data. Either way, I... will be honest and say that I didn't quite understand what exactly I should look into. The things you've pointed out for me to look into before, are things I have already looked into, and while I might not understand them all throughout, I know I can use them effectively. Right now, my networking code looks like this:

Server Create event code
Code:
//declaring the type of connection (tcp)
server_trype = network_socket_tcp;
//port number
port = 50000;
//max amount of clients that can connect to the server
max_players = 8;
//generating a server
server = network_create_server_raw(server_type, port, max_players);

//ds_list to hold a list of client sockets into
socket_list = ds_list_create();
//ds_map in which to hold 
client_data = ds_map_create();

//create a buffer with which to send information
send_buffer = buffer_create(256, buffer_fixed, 1);

Server Networking event code

Code:
///Networking
//??
type = async_load[? "type"];

//Switch statement, because needs a list of connection types... yeah
switch(type)
{
    //case for the client connecting
    case network_type_connect:
        //Refer to the connecting socket?
        client_socket_current = async_load[? "socket"];
        //Identify buffers sent?
        buffer_sent = async_load[? "buffer"];
       
        //Read the buffers sent by the joining client
        buffer_seek(buffer, buffer_seek_start, 1);
        client_id = buffer_read(buffer, buffer_string); //Client's ID number
        player_username = buffer_read(buffer, buffer_string); //Client's username
       
        //Add new player socket to the socket list
        ds_list_add(socket_list, client_socket_current);
       
        //In the client_data map, create a new key with the ID of the player, which will hold onto the user's username
        client_data[? string(client_id)] = player_username;
       
       
        buffer_write(send_buffer, buffer_string, client_id);
        buffer_write(send_buffer, buffer_string, player_username);
       
        //If there are now 2 or more users connected, send data about the new client to other clients
        if (ds_list_size(socket_list) <= 2)
        {
            for(i = 0; i < ds_list_size(socket_list); i++)
            {
                network_send_raw(socket_list., send_buffer);
            }
        }
   
   
    break;
    //case for the client disconnecting
    case network_type_disconnect:
        //Refer to the disconnecting socket?
        client_socket_current = async_load[? "socket"];
        ds_list_delete(socket_list, client_socket_current);
       
       
    break;
    //case for receiving and sending data
    case network_type_data:
        //Identify the sender
        client_socket_current = async_load[? "id"];
        //Identify buffers sent?
        buffer_sent = async_load[? "buffer"];
   
    break;
   
}
And what I'm doing here is creating a ds_list, which will contain socket data of the players and a ds_list, which will contain ID numbers and usernames (both being strings that each client will have on their side). The server would receive the ID and username data through buffers and then send it off to all clients to display... As you can probably see, I'm unfortunately stuck at making a scroll-through of clients, so that the data would be sent to all of them. Then again, I might be misunderstanding something else again and all of what I've tried to do so far might be written completely wrong. I typed it based on what I understood, from tutorials, the manual and from the information provided by users here, like you.

I can kind of understand what you mean by the way I talk. Simply put, the sheer amounts of emotion I've seen people use on other forums has kind of got to me, so I might have trouble talking 100% in concrete terms... I want to at least try and avoid being seen as offensive, because that could inevitably turn into flame wars, and I have had a bad habit of creating that, even though I've never intended to. It's all about how one's speech is interpreted at the end of the day.

@XirmiX If you ever do get this thing up and running, I think you need to include @Tsa05 in the credits. Maybe some royalties too, quantum meruit.

Edit: And Tsa05, take comfort in the legacy of your work! The posts in this forum probably see 10x their initial use as later google research.
The game's not supposed to be one to be sold or have any monetary transactions going with it. In fact, I might be infringing copyright if I do so, because the game's concept is derived from an already-existing 3D game. Moreover, I'm broke. On top of that, if I did include something like micro-transactions and there were no legal issues from me doing so, I would have to deal with cheaters A LOT more, something I as one developer simply could not handle. I mean, I do have other games in the future I want to work on as well.

If along the way Tsa's help ends up being a huge contributor to getting the game rolling, I certainly will. So far, I am still developing a connection code. I will try to mention as many people as I can recall for being of great help for open beta, or at least when the game gets completed. What I'm trying to do is a game similar in nature to Diep.io, however a tad bit more complex (and no, Diep.io was not the inspiration for this game).
 
Top