Jump to content


Photo

Gamemaker Websocket


  • Please log in to reply
120 replies to this topic

#1 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 04 December 2011 - 03:29 PM

GM Websocket v3

 

deprecated

Description

GameMaker WebSocket is small javascript code providing gamemaker to use websockets. Currently project is still in a very early alpha but includes all needed functionality. Tested with all popular browsers - chrome, firefox, opera, ie, safari (nothing missing?). Now works correctly only with chrome and firefox. I will add opera support in a week. Fully supports gm windows version server (39dll for example). Extension supports multiple connections.

Functions
 

double gmws_connect(string serverip, double serverport); // returns websocket id
gmws_clear_buffer(double wsid); //clear write buffer
gmws_write_byte(double wsid, double data); // 1 byte unsigned number 0..255
gmws_write_char(double wsid, double data); // 1 byte signed number -128..127
gmws_write_word(double wsid, double data); // 2 byte unsigned number 0..65535
gmws_write_short(double wsid, double data); // 2 byte signed number -32768..32767
gmws_write_dword(double wsid, double data); // 4 byte unsigned number 0..4294967295
gmws_write_int(double wsid, double data); // 4 byte unsigned number -2147483648..2147483647
gmws_write_float(double wsid, double data); // 4 byte floating point number
gmws_write_double(double wsid, double data); // 8 byte floating point number
gmws_write_string(double wsid, string data); // null-terminated string (1 byte per char code, last byte - 00)
gmws_write_widestring(double wsid, string data); // null-terminated unicode string (2 bytes per char code, last bytes 00 00)
double gmws_send(double wsid); // return 0 if disconnect, return -1 if no data was sent, return buffer size normally
double gmws_read_byte(double wsid); // return 0 if no data in recv buffer
double gmws_read_char(double wsid);
double gmws_read_word(double wsid);
double gmws_read_short(double wsid);
double gmws_read_dword(double wsid);
double gmws_read_int(double wsid);
double gmws_read_float(double wsid);
double gmws_read_double(double wsid);
string gmws_read_string(double wsid); // return "" if no data in recv buffer
string gmws_read_widestring(double wsid)
double gmws_recv(double wsid); // return 0 if disconnect, return -1 if no data was received, return buffer size normally (real sent size = returned size + 8 bytes)
double gmws_get_state(double wsid); // 0 - connecting, 1 - connected, 2 - disconnecting, 3 - disconnected;

Guide
1) Launch gmws.exe (websocket traffic "translator" with params gmws.exe ip1 port1 ip2 port2, where ip1 port1 - client connects to (example 127.0.0.1 8080) and ip2 port2 - server (for example 39dll) listens at (example 127.0.0.1 8081). Default values (if no params set) - 127.0.0.1 8080 127.0.0.1 8081
2) Launch your server
3) Connect with html5 client to server

Downloads [reupload - 26.01.12]
GM WebSocket Extension - gmws.gex
Websocket Traffic "Translator" - gmws.exe
Example (server - 39dll) - gmwsexample.zip

 

 

gmws Sources
As promised. Gmws (websocket protocol) c/cpp sources. They are not finished, not commented, not organised. Ill post it in 1st post when organise code better.

 

Bugs, wishes, suggestions. Please give me feedback.


Edited by Demion, 09 October 2013 - 07:15 PM.

  • 3

#2 Barling

Barling

    GMC Member

  • New Member
  • 122 posts

Posted 05 December 2011 - 08:11 PM

Is there an example of how to use the C++ server?
Also can any server work? Even a GM server?

Because I tried with a GM server, and I noticed I was able to establish a connection.

Edited by Barling, 05 December 2011 - 08:11 PM.

  • 0

#3 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 05 December 2011 - 09:13 PM

You need to compile c/c++ server to use it. Sources are included in first post. About GM server. Ill made "proxy" app to make GM server work with GM html5 client soon. Thanks.

Edited by Demion, 05 December 2011 - 09:22 PM.

  • 1

#4 Barling

Barling

    GMC Member

  • New Member
  • 122 posts

Posted 05 December 2011 - 10:19 PM

Yeah but I was able to establish a connection with my GM server.
Also, your help document appears to be empty, and there is no documentation
on how to use the C/C++ server (as in, how to code the actual server, what functions to use, etc.)

It can be rather confusing for first time users.

For example, how do we receive and send messages in the C++ example
back to the GMHTML5 client?

Edited by Barling, 05 December 2011 - 10:35 PM.

  • 0

#5 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 08 December 2011 - 12:01 AM

Rewritten most code. Released v2. All information in 1st post. Fully support 39dll based servers (gm for windows). Ill make c/c++ server example soon. Please test and give bugs, wishes, suggestions, feedback. Thanks.

---

Tested with all popular browsers - chrome, firefox, opera, ie, safari (nothing missing?). Now works correctly only with chrome. I will add firefox and opera support in 1-2 days.

Edited by Demion, 11 December 2011 - 11:39 PM.

  • 1

#6 Greenblizzard

Greenblizzard

    GMC Member

  • GMC Member
  • 350 posts
  • Version:GM:Studio

Posted 09 December 2011 - 07:05 PM

EDIT2:
Never mind, it works!
First of all, didn't see that you used two different, but similar ports in your guide (8080 and 8081), so I used the same port in both places.. I had also changed the port for the client to connect to in the wrong object.

I don't have a lot of experience with online in Game Maker, and with this system that makes it slightly more complex than just 39dll, and having to run an exe with parameters(which I've never done before), this ended up being a bit confusing.

Anyway, well done, and thanks for making this :biggrin:
EDIT1:

Tried to run both server and client without the gmws.exe, and got the same result. Maybe I just didn't run the exe the right way or set the parameters right.

How is it supposed to be done?


ORIGINAL POST:

This is neat!
If I only could get it to work properly...
I use the 39dll based server approach and am able to get the server and client connected, but they won't communicate.

When I try to make the client send a message, the gmsw_send() function returns -1, meaning no data was sent. What could be causing this?

Edited by Greenblizzard, 09 December 2011 - 10:12 PM.

  • 0

#7 lukeescude

lukeescude

    GMC Member

  • GMC Member
  • 707 posts
  • Version:GM:Studio

Posted 10 December 2011 - 02:57 AM

Could you explain what the websocket traffic "translator" is?

I'm not entirely sure if that's part of the client or the server... You make it sound like it's both.
  • 0

#8 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 10 December 2011 - 09:18 AM

Client should connect to gmws.exe (to ip1:port1) and gmws.exe decodes websocket traffic and forwards it to your original 39.dll (or other) server (to ip2:port2). So gmws.exe should be used only on server side. And you cant use 2 same ports. Becuase you cant listen to two same ports on windows. Maybe Ill make dll / extension for win32 game maker to use it without external .exe.

---

gmsw_send() function returns -1

You use it just after connect in create event? -1 returns if there is no data in buffer or mostly if websocket is not finished connecting. So I recommend you sending your first packet like this
create event - connect, alarm[0] = room_speed.
alarm0 - send your first packet
or in step event
Its a bit confusing but i think it is becuase of websocket architecture. After you call connect it doestn wait until connection is fully established. So you should wait ~1sec.

Edited by Demion, 10 December 2011 - 09:42 AM.

  • 0

#9 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 11 December 2011 - 05:13 PM

the function gmws_read_string doesn't exist on .gex
  • 0

#10 Greenblizzard

Greenblizzard

    GMC Member

  • GMC Member
  • 350 posts
  • Version:GM:Studio

Posted 11 December 2011 - 05:36 PM

@Demion
I've been struggling with ports and getting a client to connect to the server with my external ip.

After a while, I found canyouseeme.org.
There I found that it could only "see" the port that the server listens to when the server is running, no matter if gmws.exe is running or not.
It could not see the port the client is supposed to connect to even if gmws.exe was running.

Have you tested with a client connecting to the server's external ip and got it to work?


I'm also not 100% sure if I set gmes.exe's parameters correctly. This is what I currently have as target in a shortcut:
"filepath\gmws.exe" 127.0.0.1 port1 127.0.0.1 port2

*actual ports are replaced by port1 and port2

Edited by Greenblizzard, 11 December 2011 - 05:37 PM.

  • 0

#11 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 11 December 2011 - 08:11 PM

the function gmws_read_string doesn't exist on .gex

Will be fixed in release v3. For just now you can add function by yourself.

Have you tested with a client connecting to the server's external ip and got it to work?

Yes it works with external ip and local too. It's hard to say whats your problem, you can contact me privately and Ill try to figure it out.

Edited by Demion, 11 December 2011 - 08:20 PM.

  • 0

#12 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 11 December 2011 - 10:50 PM

the function gmws_read_string doesn't exist on .gex

Will be fixed in release v3. For just now you can add function by yourself.

Have you tested with a client connecting to the server's external ip and got it to work?

Yes it works with external ip and local too. It's hard to say whats your problem, you can contact me privately and Ill try to figure it out.


when is v3 releasement day?
  • 0

#13 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 11 December 2011 - 11:45 PM

Release v3
- firefox support! (latest version)
- add gmws_write_string / gmws_read_string
- fix gmws.exe parameters read
- add gmws.exe config console output

Next release (in a week) : opera support, buf fixes, optimization etc.

Edited by Demion, 11 December 2011 - 11:53 PM.

  • 1

#14 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 12 December 2011 - 12:20 AM

Release v3
- firefox support! (latest version)
- add gmws_write_string / gmws_read_string
- fix gmws.exe parameters read
- add gmws.exe config console output

Next release (in a week) : opera support, buf fixes, optimization etc.


AWESOME
  • 0

#15 lukeescude

lukeescude

    GMC Member

  • GMC Member
  • 707 posts
  • Version:GM:Studio

Posted 12 December 2011 - 12:31 AM

Yes, awesome!.

I'll start using this as soon as possible. Keep up the good work!
  • 0

#16 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 18 December 2011 - 10:56 PM

mmmm this isn't working for me i run the gmws.exe first then the server and then the client and it doesn't work : / can you tell me what's the thing I'm doing wrong?
  • 0

#17 Orbitguy

Orbitguy

    UNS Lead Guy

  • GMC Member
  • 348 posts
  • Version:GM:Studio

Posted 19 December 2011 - 05:25 AM

mmmm this isn't working for me i run the gmws.exe first then the server and then the client and it doesn't work : / can you tell me what's the thing I'm doing wrong?


Yeah I had a similiar issue, figured I probably wasn't running the right files... Was using firefox.
  • 0

#18 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 19 December 2011 - 12:43 PM


mmmm this isn't working for me i run the gmws.exe first then the server and then the client and it doesn't work : / can you tell me what's the thing I'm doing wrong?


Yeah I had a similiar issue, figured I probably wasn't running the right files... Was using firefox.


what can i do?
  • 0

#19 oneSOB

oneSOB

    GMC Member

  • New Member
  • 33 posts

Posted 19 December 2011 - 03:59 PM

I used to use websockets with GM like you, but then I took an arrow the knee

Also did you even tink about releasing the gmws.exe source code becase some people would like to use a c++ server but use it only for non websocket traffic (this was a bad explanation)

Let me further explain

Gm Client -> direct data -> C++ Server
HTML5 Version -> websocket data -> C++ Server

On the C++ server it will accept connections using the 39dll like normally

In the C++ server it will never know wether a connection was from a websocket or a .exe
making the server easier to program and a streamlined application

---------------------------------------------------------------------------------------------------------------------------------
Write server code once
Allow several different types of game interfaces to use it
Get ads on ur site and charge membership
???????????????????
Profit
  • 0

#20 Orbitguy

Orbitguy

    UNS Lead Guy

  • GMC Member
  • 348 posts
  • Version:GM:Studio

Posted 21 December 2011 - 04:13 AM



mmmm this isn't working for me i run the gmws.exe first then the server and then the client and it doesn't work : / can you tell me what's the thing I'm doing wrong?


Yeah I had a similiar issue, figured I probably wasn't running the right files... Was using firefox.


what can i do?


Well tonight I finally had the time to sit down and work at this. I did get it to work after about an hour, then realizing that my family had bought a new router while I was at college and I had to reportforward etc...

Anyways, it's rather hard to tell if it has connected because there is no type of indication programmed in the client or the server.

Really all you need to do is 1. Make sure you are port forwarded. and 2. Change the IP in the html5 client to 127.0.0.1 or your own IP because it's still set to his IP.
If it still doesn't work I would check that you have all of the extensions connected to each file.

I'm going to work on this more and see if I can't create some interfaces similiar to my other online projects, to give this example some more life. Great job creating this btw.
  • 0

#21 Crhonos

Crhonos

    GMC Member

  • GMC Member
  • 235 posts
  • Version:GM:Studio

Posted 21 December 2011 - 05:06 PM

Have i ever told that i love you and you are a genius ?
What you done was just what everyone needed =D
Thanks.

How do i change the params of the Gmws translator ?

Edited by Crhonos, 21 December 2011 - 05:19 PM.

  • 0

#22 oneSOB

oneSOB

    GMC Member

  • New Member
  • 33 posts

Posted 21 December 2011 - 05:17 PM

I have a question
Have you considered releasing the source of the Gmws Proxy/Translator
I would love to mess around with it and custom build it into my server

Example

MyGame.exe -> 39Dll -> C++ Server
MyGame.php -> gmws -> C++ Server

and if coded right no one knows the difference between broswer based play or exe
  • 0

#23 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 22 December 2011 - 12:49 PM

Have you considered releasing the source of the Gmws Proxy/Translator

Sorry for delay. Ill release "translator" gmws sources next release (+Opera support). I was very busy last week. I hope Ill release it this weekends.

Edited by Demion, 25 December 2011 - 04:05 AM.

  • 0

#24 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 22 December 2011 - 01:15 PM

Sorry for delay. Ill release "translator" gmws sources next release (+Opera support). I was very busy last week. I hope Ill release it this weekends.


gmws doesn't work for me :S

i run gmws then server and then client and doesn't work
  • 1

#25 thedyingdragon

thedyingdragon

    GMC Member

  • GMC Member
  • 23 posts

Posted 22 December 2011 - 01:20 PM

Ill release "translator" gmws sources next release (+Opera support).


I gotta say that would be pretty sweet as I have been trying to incorporate
it into my server as well

Its been a bit tricky though and im sure the translator may help me out
Thanks so much for this!!! ::lmao::
  • 0

#26 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 22 December 2011 - 01:25 PM

gmws doesn't work for me :S


Server / client with win32 gamemaker and 39dll (no html5) work for you? If problem only in gmws contact me privately.

Edited by Demion, 22 December 2011 - 01:28 PM.

  • 0

#27 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 22 December 2011 - 01:28 PM


gmws doesn't work for me :S


Server with win32 gamemaker and 39dll (no html5) work for you? If problem only in gmws contact me privately.


oh since it was set to your IP it didn't work XD. know it works
  • 0

#28 Barling

Barling

    GMC Member

  • New Member
  • 122 posts

Posted 24 December 2011 - 08:26 PM

I get this error:

Error: WebSocket is not defined
Source File: http://127.0.0.1:512...ml5game/gmws.js
Line: 45


Line 45 of gmws.js:

Error: WebSocket is not defined
Source File: http://127.0.0.1:512...ml5game/gmws.js
Line: 45


whenever I use this in my game:
ws = gmws_connect("127.0.0.1", 8080);

EDIT:
Aw, it works in chrome.
I'm running Firefox 9.01.

Is websockets disabled in firefox or something?

Edited by Barling, 24 December 2011 - 11:22 PM.

  • 0

#29 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 25 December 2011 - 03:17 AM

Is websockets disabled in firefox or something?

You are using latest release? Firefox uses MozWebSocket not WebSocket. But release v3 checks browser id and uses MozWebSocket for latest Firefox. Maybe problem in browser detect function. Ill check it and contact you later. Thanks.

Edited by Demion, 25 December 2011 - 04:05 AM.

  • 0

#30 Debels

Debels

    GMC Member

  • GMC Member
  • 2635 posts
  • Version:GM:Studio

Posted 25 December 2011 - 03:38 AM

You are using latest release? Firefox uses MozWebSocket not WebSocket. But release v3 checks browser id and uses MozWebSocket for latest Firefox. Maybe problem in browser detect function. Ill check it and contact you later. Thanks.


Demion MERRY CHRISTMAS!, keep up the good work with GM:WebSocket =D
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users