Jump to content


Photo

39dll V2.5


  • Please log in to reply
2510 replies to this topic

#2441 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 13 April 2011 - 07:03 PM

...

Oh. My. God.

Okay, TCP uses connections. You need to connect when you start the game (or after starting from the menu). If the game fails to connect the the server, you cannot continue. If you do connect, you keep that socket ID (return value of tcpconnect()) and use it to send messages to the server. You only connect once! When the game is closing (or quitting to the menu), you close the connection.

Understood? Good.
  • 1

#2442 sinny

sinny

    GMC Member

  • New Member
  • 17 posts

Posted 22 May 2011 - 10:26 AM

I have no idea if this is an appropriate thread to use, but it's 39dll-related so I can only hope.

I've been trying to get some netcode working for months now. I was originally coding in Lua, Python, then Java, then I tried Construct (thinking a pre-made multiplayer solution might work) and finally Game Maker. GM looked really promising, but having got 39DLL working locally I tried it between two computers and it failed miserably.

I'm getting tired. ¬_¬

I've opened the ports on my machine, I have no firewalls, and despite being behind a router the ports are opened there too and I've connected to just about every reasonable IP address I can think of. Nothing. What am I missing here? I assume people have managed to use 39dll successfully, judging by the posts in this thread?

EDIT - Wait, wait, it appears what I needed to do was post my problem publicly, then GameMaker would fix itself, rendering me a complete idiot. Good stuff. All fixed.

Edited by sinny, 22 May 2011 - 10:38 AM.

  • 1

#2443 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 05 June 2011 - 07:37 AM

I looked at the example for getting the IP
/*
script will return your network ip address. It connects to whatismyip.com:80 which sends
the ip address in the form of a http payload packet.
*/
var tcp;
tcp = tcpconnect("whatismyip.org", 80, 0);
if(!tcp)return "";
setformat(tcp, 1, chr(13) + chr(10) + chr(13) + chr(10)); //set format to text mode to receive double blank lines (the whole header file)
//send get request
clearbuffer();
writechars("GET / HTTP/1.1" + chr(13) + chr(10));
writechars("Host: whatismyip.org" + chr(13) + chr(10));
writechars("Connection: close"+chr(13) + chr(10));
writechars("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-alambik-script, application/x-alambik-alamgram-link, */*"+chr(13)+chr(10));
writechars("Accept-Language: en-us"+chr(13) + chr(10));
writechars("User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)" +chr(13) + chr(10));
sendmessage(tcp);

a = receivemessage(tcp); //receive http header (and ignore)
a = receivemessage(tcp, 16); //receive payload data
closesocket(tcp);
return readchars(bytesleft()); //return the payload data (ip address in this case)
but I cant understand a thing from it!

I want to send some data to a php page that I'll obtain with _GET later - just like as if I typed in the url example.com/a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds...
How do I do this? I tried


var tcp;
tcp = tcpconnect("example.com", 80, 0);
clearbuffer();
writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds" + chr(13) + chr(10));
sendmessage(tcp);
//...
but it doesnt work. Any help is apreciated.
  • 0

#2444 Medo42

Medo42

    GMC Member

  • GMC Member
  • 220 posts

Posted 05 June 2011 - 08:40 AM

I looked at the example for getting the IP

/*
script will return your network ip address. It connects to whatismyip.com:80 which sends
the ip address in the form of a http payload packet.
*/
var tcp;
tcp = tcpconnect("whatismyip.org", 80, 0);
if(!tcp)return "";
setformat(tcp, 1, chr(13) + chr(10) + chr(13) + chr(10)); //set format to text mode to receive double blank lines (the whole header file)
//send get request
clearbuffer();
writechars("GET / HTTP/1.1" + chr(13) + chr(10));
writechars("Host: whatismyip.org" + chr(13) + chr(10));
writechars("Connection: close"+chr(13) + chr(10));
writechars("Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-alambik-script, application/x-alambik-alamgram-link, */*"+chr(13)+chr(10));
writechars("Accept-Language: en-us"+chr(13) + chr(10));
writechars("User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)" +chr(13) + chr(10));
sendmessage(tcp);

a = receivemessage(tcp); //receive http header (and ignore)
a = receivemessage(tcp, 16); //receive payload data
closesocket(tcp);
return readchars(bytesleft()); //return the payload data (ip address in this case)
but I cant understand a thing from it!

I want to send some data to a php page that I'll obtain with _GET later - just like as if I typed in the url example.com/a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds...
How do I do this? I tried


var tcp;
tcp = tcpconnect("example.com", 80, 0);
clearbuffer();
writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds" + chr(13) + chr(10));
sendmessage(tcp);
//...
but it doesnt work. Any help is apreciated.


You forgot the HTTP version string after the path, e.g.:
writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10));

Edited by Medo42, 05 June 2011 - 08:41 AM.

  • 1

#2445 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 05 June 2011 - 10:11 AM

You forgot the HTTP version string after the path, e.g.:

writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10));

Thanks, I have included it - it still doesn't work - what else I need to do?
  • 0

#2446 Medo42

Medo42

    GMC Member

  • GMC Member
  • 220 posts

Posted 05 June 2011 - 10:32 AM


You forgot the HTTP version string after the path, e.g.:

writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10));

Thanks, I have included it - it still doesn't work - what else I need to do?

Now that you mention it, a second CRLF would not be a bad idea, so that the server actually knows you're finished sending the request headers.
writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10) + chr(13) + chr(10));

  • 1

#2447 regular

regular

    GMC Member

  • New Member
  • 399 posts

Posted 05 June 2011 - 10:39 AM



You forgot the HTTP version string after the path, e.g.:

writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10));

Thanks, I have included it - it still doesn't work - what else I need to do?

Now that you mention it, a second CRLF would not be a bad idea, so that the server actually knows you're finished sending the request headers.
writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10) + chr(13) + chr(10));

Again no result. :/ I've also tried with HTTP/1.1 as in the example, but there seems to be something else missing.
  • 0

#2448 Medo42

Medo42

    GMC Member

  • GMC Member
  • 220 posts

Posted 05 June 2011 - 07:59 PM




You forgot the HTTP version string after the path, e.g.:

writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10));

Thanks, I have included it - it still doesn't work - what else I need to do?

Now that you mention it, a second CRLF would not be a bad idea, so that the server actually knows you're finished sending the request headers.
writechars("GET /a.php?argument1=blahblahblah&argument2=43&argument3=fdsfds HTTP/1.0" + chr(13) + chr(10) + chr(13) + chr(10));

Again no result. :/ I've also tried with HTTP/1.1 as in the example, but there seems to be something else missing.

I'd have to see the context of your code to be sure, but I guess you are using the default format. You have to make sure that what is sent to the server is exactly the string you prepare in the call to writechars at the moment, either by setting the socket's format to 2 (raw) or by using format 1 with CR/LF/CR/LF as delimiter, like the example code does. In that case you can leave out the CR/LF/CR/LF from the end of your string of course.
  • 0

#2449 LedgendaryHero

LedgendaryHero

    GMC Member

  • New Member
  • 648 posts

Posted 14 June 2011 - 05:16 PM

Hello everybody. I avoided 39dll too long, and when i actually tried it i was very surprised to see how easy it is. The whole short/byte/etc. thing scared me off at first, but it's actually really, really easy and cool.

Here's a simple question:
Can multiple machines connect to the server through a single port with different IP addressed? Aka, would each client have to somehow get a unique port to connect to the server that's not already being used? I understand what ports are and how they work (which leads me to believe only one connection is allowed to a port at any given time), but I don't want to go to the trouble of figuring out how to connect to a random port number that hasn't already been taken (I'd guess you'd have to connect to some sort of server that keeps track of which port numbers have been handed out, which sends a valid port number. would this be the wrong idea?). Any help?

Edited by LedgendaryHero, 14 June 2011 - 05:17 PM.

  • 0

#2450 Medo42

Medo42

    GMC Member

  • GMC Member
  • 220 posts

Posted 15 June 2011 - 08:11 AM

Can multiple machines connect to the server through a single port with different IP addressed?

Yes. You can even connect to the same server port from the same IP multiple times, as long as the source port is different (and unless you specify the source port yourself, the operating system takes care of that).
  • 0

#2451 LedgendaryHero

LedgendaryHero

    GMC Member

  • New Member
  • 648 posts

Posted 15 June 2011 - 08:28 AM

Well i'm not sure if this is related, but i've, since my post, toyed around with 39dll and am doing great. I've got lobby with syncing games and a side chat. But i experience a strange problem: The chat messages the first client to connect (i tried up to 3 at a time) send super fast and are received just as quickly on all three clients. However, chat messages sent on the other two clients take an unknown amount of time to 'send'; All the clients chat's are updated at the exact same time, so it's not simple lag; it seems as if the other player's chat messages just are having a hard time getting through the server.

I use a server program to process all the data; when you press enter on a client, it sends the player name and the keyboard_string to the server. simply, it's then copied into a new message that's sent to everyone. Now why do i experience this delay in message processing? It processes client 1's messages as quickly as i press enter on everybody's screen, yet the other clients' messages take what seems to be a pre-measured time to be delivered. Even if i were to send a message on client2 and then one on client 1, client 1's message is put through first (unless, like i said, that seemingly allotted amount of time is up).

What could be causing this? I really don't think it's lag. It feels almost like a port error; on all the clients, they attempt to connect to the same port on the server. Is this a bad thing?

I'm sorry, but if so, how should i get a new port for each client? How CAN i until after they've connected on some port? should i have one port dedicated to port assignment? They, as soon as they hit the lobby, connect to that port where they are given a new port based on an array and quickly jump out of the connection?

Edit: ------------

I got it working just fine by using objects to do the computing as players instead of just running a for loop. Can anyone explain why the for loop wasn't really working except for the first client? I ran checks to make sure it was cycling all the wall through, and it was. It even showed a delay in receiving the message from client2 and then even after it processed it, there was a delay before it was received by the clients. Talk about odd?

Also, now that i look at tcplisten again, the fact you specify how many people can be waiting pretty much means it's perfectly fine for more than one person to connect through one port, huh? :)
Thanks for your post it did help.

Edited by LedgendaryHero, 15 June 2011 - 06:27 PM.

  • 0

#2452 Loric

Loric

    GMC Member

  • GMC Member
  • 6 posts
  • Version:GM8

Posted 19 June 2011 - 08:08 PM

Hi, I looked at the source code...

Is this ok? Or little memory leaks?

// tools.cpp
// line: 161

int CTools::BinRead(HANDLE hwnd, int size, CBuffer*out)
{
	DWORD a;
	char*b = new char[size]; // new char array
	ReadFile(hwnd, b, size, &a, NULL);
	out->StreamWrite(b, a);
	delete b; // shoud be delete[] b;
	return a;
}

  • 0

#2453 Shocker51374

Shocker51374

    GMC Member

  • New Member
  • 27 posts

Posted 21 June 2011 - 12:08 PM

I don't know if anyone is interested in it, but...
I made 39dll work in Java - http://gmc.yoyogames...dpost&p=3773636
Could be useful for some people.

Edited by Shocker51374, 21 June 2011 - 12:09 PM.

  • 1

#2454 Chubysnow

Chubysnow

    GMC Member

  • New Member
  • 13 posts

Posted 07 July 2011 - 01:13 AM

I believe I am doing something wrong. I want to compile it with code block so I open up the .cbp with code blocks and the option Compile Current File is greyed out. I click on a cpp within the cbp and I click compile all this gives me is a bunch of code. What do I do with all that code? How do I use this in game maker?
  • 0

#2455 tim.vangehugten

tim.vangehugten

    GMC Member

  • GMC Member
  • 72 posts

Posted 22 July 2011 - 04:09 PM

I believe I am doing something wrong. I want to compile it with code block so I open up the .cbp with code blocks and the option Compile Current File is greyed out. I click on a cpp within the cbp and I click compile all this gives me is a bunch of code. What do I do with all that code? How do I use this in game maker?


which compiler do you use?
  • 0

#2456 zehevi

zehevi

    GMC Member

  • GMC Member
  • 637 posts
  • Version:GM8

Posted 09 August 2011 - 08:13 AM

Hi,
I'm trying to used both TCP and UDP within my game to maximize performance.
The problem is, when the Host receive an incoming TCP connection it attaches the socket to the player object
Now when there is an incomming UDP connection the Host creates a new socket and that socket must be attached to the same player object
but I cant find a way to find the right TCP socket/ Player object to attach the UDP socket to.

If anyone knows how to solve this issue I would be really grateful.

Thanks in advance.
  • 0

#2457 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 09 August 2011 - 04:34 PM

when there is an incomming UDP connection

UDP connection?
  • 0

#2458 sabriath

sabriath

    12013

  • GMC Member
  • 3147 posts

Posted 09 August 2011 - 09:14 PM

when there is an incomming UDP connection

UDP connection?

What TMN is trying to say is...UDP is connectionLESS. It means that you can't have a UDP connection (in a standard way).

I assume you are opening a single TCP port for listening on the server, and all your clients "tcpconnect" in to that port. I couldn't imagine how you are doing your UDP scripts, but the way I would do it is:

1. Server should open a couple UDP ports as you do with the TCP ports for listening.

2. When a client 'tcpconnect's to the server, the server should send the client 2 pieces of information:
a - a random number unique to the connection created by the server, called the 'ID'
b - one of the UDP port numbers, round-robin fashion based on lowest populated first

3. The server will create the player object and give it the TCP socket, UDP out-port value, and ID. It will also add the player's instance id to the UDP port map, mapping it to the ID as a key. The player object will be given a timer, explained in step 5.

4. The client will then open its own UDP port and send a message that contains the ID and a single byte code used to denote a "see me".

5. The server's object that listens for incoming connections should also "scan" the UDP sockets for messages. If it receives a message, it will check the ID against the UDP map and hand the message off to the player object instance. If that message is a "see me", it will store lastinIP and lastinPort to the player's instance object (at which point it will turn off the timer that was set in step 3). If the timer goes off, a message is sent over TCP telling the client that it needs another "see me" code over UDP sent (and the timer is set again and step 5 repeated).

6. The client and server now have information of TCP and UDP contact information. Make sure you set up a timer for each side that "pings" each other on UDP in order to keep the fake connection active. Also understand that UDP is not guaranteed.

Edited by sabriath, 09 August 2011 - 09:16 PM.

  • 1

#2459 zehevi

zehevi

    GMC Member

  • GMC Member
  • 637 posts
  • Version:GM8

Posted 10 August 2011 - 04:36 AM

Sabriath, thanks for the detailed comment.
After 2 days of tests I have done most of the things you mentioned
But now this is what I dont understand, this is how you are suppose to send message:
sendmessage(socket, ip, port);

The IP and port are no trouble but what is the socket value? And what is the function to retrieve that value? (udpconnect? with both host and client?)

Also, when sending a messege to the host, do I send through the hosts forwarded port or the clients port?
  • 0

#2460 sabriath

sabriath

    12013

  • GMC Member
  • 3147 posts

Posted 10 August 2011 - 08:51 AM

Sabriath, thanks for the detailed comment.
After 2 days of tests I have done most of the things you mentioned
But now this is what I dont understand, this is how you are suppose to send message:

sendmessage(socket, ip, port);

The IP and port are no trouble but what is the socket value? And what is the function to retrieve that value? (udpconnect? with both host and client?)

Also, when sending a messege to the host, do I send through the hosts forwarded port or the clients port?

"socket" is the value of the socket you are sending FROM....IP and Port are the values of the computer you are sending TO. You retrieve this value by using "udpconnect" (which actually should be re-written as "udplisten" because it doesn't actually connect to anything).
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users