1
\$\begingroup\$

I am making a gamemaker multiplayer game using 39dll's tcp sockets. As I want to host the server (and my javascript knowledge is a lot better), I use node.js for the server. I have already got gamemaker to connect to the server and send data, but now I have a problem with receiving data. After reading a lot, it seems that I need to do that like so: sock=tcpaccept(global.tcpConnection,1);. If sock is a negative number, the creation of the 'listening' interface failed. It returns me the number -10022. I can not find much information about it, so if anyone knows why this problem occurs and how to fix it would be very nice.

I am just making a normal gamemaker 8.1 game, no HTML5 game (I'd rather script that myself, not with gamemaker as I am really disliking it).

My server code:

var net = require('net');
var server = net.createServer(function(socket){
    console.log('connection made');
    socket.on('data', function(d){
        console.log(d.toString());
        socket.write(d.toString());
    });
    socket.on('error', function(e){console.log(e)});
    socket.on('close', function(){console.log('Socket closed');});
    socket.write('hhhaaannbikbkm');
}).listen(process.env.VCAP_APP_PORT||8080);

GML code (in the game start event):

dllinit(0,true,true);
global.username = get_string("Gebruikersnaam:","");
global.serverip = get_string("Server IP:","127.0.0.1");
global.serverport = get_integer('port', 8080);

global.tcpConnection = tcpconnect(global.serverip, global.serverport, 1);
setformat(2, '<!SEP!>');
if(!tcpconnected(global.tcpConnection)){
    show_message("Connection failed");
    game_end();
} else {
    setnagle(global.tcpConnection,1);
    clearbuffer();
    writestring(global.username, false);
    sendmessage(global.tcpConnection, 1, 1);
    while(true){
        var sock, size, cnt;
        sock=tcpaccept(global.tcpConnection,1);
        show_message(sock);
        //if (sock <=0) break;
        setsync(sock,0);//block untill new package
        size = receivemessage(sock, 0);
        show_message(size);
        //setsync(sock,1);//unblock socket
        cnt = readstring(0, '<!SEP!>');
        if(cnt!=''){
            show_message(cnt);
            clearbuffer();
            writestring(cnt, false);
            sendmessage(global.tcpConnection, 1, 1);
        }
    }
}
\$\endgroup\$
0
\$\begingroup\$

I already fixed this like a week ago or so. I just don't need to call sock=tcpaccept(global.tcpConnection,1);, but just receive the messages with receivemessage(global.tcpConnection, 9999999);

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.