Jump to content


Photo

Extension: 39js (Socket.io)


  • Please log in to reply
72 replies to this topic

#1 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 27 September 2011 - 04:56 PM

39js
39js is a javascript implementation of the 39dll for GMhtml5. The overall aim is to allow current Game maker games based on 39dll the ability to convert to Html5 with minimal (if any) code changes. Currently 39js is still in a very early alpha stage but includes most of the functionality needed to make multiplayer html5 games in Game Maker. It uses Socket.io to support the widest possible range of browsers and devices (tested and working on iphone and most major Browsers).

Example (if my computer is on):
http://amorri40.gith...js/examplegame/

The example is made by Revel from this topic: http://gmc.yoyogames...howtopic=332957 the client gmk was simply imported into gmhtml5 and runs just like it would with 39dll, but the server was slightly changed and made into a javascript file running on nodeJs.

Download from Github:
https://github.com/amorri40/39js

At the moment i'm currently investigating alternative ways of developing the server in Game Maker rather than rewriting slightly for Javascript. Only the basic functions have been implemented so far, the rest of the functions will be implemented when the server can be developed in GM with minimal changes from the original example.

You can download the client example in the github (import in gmhtml5) and you can run the server by running the bat file in the server folder. The API is the same as 39dll (or will be when the rest are implemented).

Let me know if you need any help
  • 9

#2 HighQuality

HighQuality

    Wuka World Creator

  • GMC Member
  • 610 posts
  • Version:GM:HTML5

Posted 27 September 2011 - 05:15 PM

Would love to see this getting finished, if you somehow could get it working with a non-modified 39dll-based server that'd be amazing.

Anyways, great work so far, looking forward to updates :)
  • 0
Posted Image Posted Image
Wuka World 2 - Currently in development
Find out more at www.nevereal.net

#3 BlaXun

BlaXun

    Slime Online Creator

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

Posted 27 September 2011 - 05:29 PM

...impressive. Damn, trying this right now. You made my day <3

I'll check this thread regulary
  • 0

iBNKRoX.png


#4 TerraFriedSheep

TerraFriedSheep

    GMC Member

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

Posted 27 September 2011 - 05:57 PM

Nice to see some online multiplayer progress made so early on after the release of beta, it's satisfying seeing the little squares move around in their first grasp for multiplayer life :thumbsup:
  • 0

#5 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 27 September 2011 - 11:19 PM

Well, doesn't seem to do anything beyond showing me some messages boxes when I try your link directly, and when I downloaded it and followed your instructions by running the batch file, it threw an error (something to do with process.nextTick).

Also, the example you're using is somewhat...average. It doesn't even check to see if the connection was successful. If you'd like to work with something more established, the Basic Network example I made a while ago might be better: http://bit.ly/oRbCNa

Additionally, the way you've setup the server is quite strange. Personally I'm thinking using PHP with a MySQL database as the back-end is a more logical way to go...perhaps it's time the GMC outgrew 39dll a little ;)
  • 0

book_forum.png


#6 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

Posted 27 September 2011 - 11:27 PM

Additionally, the way you've setup the server is quite strange. Personally I'm thinking using PHP with a MySQL database as the back-end is a more logical way to go...perhaps it's time the GMC outgrew 39dll a little ;)


That is probably too slow for real-time games, no?
  • 0
"Let's leave the classics for your parents." - KC LC

#7 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 28 September 2011 - 01:31 AM

I don't see why it would be...the main issue for both 39dll or PHP is the time it takes for the message to travel from the client's PC to the server. No matter which method you use, there's still that ping time.

If you organize the structure well enough, it becomes irrelevant if it's a real-time game or not ;)
  • 0

book_forum.png


#8 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9421 posts
  • Version:Unknown

Posted 28 September 2011 - 02:06 AM

The difference in connection type means an HTTP request is quite a bit slower than a socket connection.

However, the trick is to make the game fake while it waits.
  • 0

#9 Seki

Seki

    GMC Member

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

Posted 28 September 2011 - 02:08 AM

OMG, just what i needed, thanks... this might help out... Trying to make a native app work with this xDD... gonna be interesting :D
  • 0


PixelJolt: Developement Blog


#10 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

Posted 28 September 2011 - 02:16 AM

The difference in connection type means an HTTP request is quite a bit slower than a socket connection.

However, the trick is to make the game fake while it waits.


I was thinking about this too when I wrote that. But PHP supports sockets.
  • 0
"Let's leave the classics for your parents." - KC LC

#11 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 28 September 2011 - 02:48 AM

Thanks HighQuality , BlaXun and Soulsnatcher was nice seeing you guys check out the example, even if it was just a rectangle moving on screen :thumbsup:

@True Valhalla : Sorry I switched off nodeJS for a while. I don't currently have a server/vps that i can let nodeJS run so it will be off at times.
It was just a very simple example which was supposed to look like this if my server was up:
Spoiler

The players weren't being destroyed as the game end event doesn't seem to work :confused:

Any chance I could distribute your basic networking example with 39js? It looks great :biggrin:

I setup the server in a strange way or a number of reasons, but mainly I wanted to keep most of the original code from the server example, so most of the code is the same, I also prefer javascript to php and would like to be able to run gmhtml5 as servers in nodeJS (with a simulated browser environment).

Also the output from nodeJS would be very useful as i can't reproduce it (works on mac and windows for me).

Also about using a php server instead of nodeJS, there is a websocket library for php here: http://code.google.com/p/phpwebsocket/ which would be a good starting place.

@Seki what do you mean by native app? If you need any help give me a shout
  • 0

#12 Barling

Barling

    GMC Member

  • GMC Member
  • 127 posts

Posted 28 September 2011 - 02:58 AM

server no work!

node.js:208
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module 'socket.io-client'
    at Function._resolveFilename (module.js:327:11)
    at Function._load (module.js:272:25)
    at Module.require (module.js:350:17)
    at require (module.js:361:17)
    at Module._compile (module.js:425:26)
    at Object..js (module.js:443:10)
    at Module.load (module.js:344:31)
    at Function._load (module.js:303:12)
    at Module.require (module.js:350:17)

Edited by Barling, 28 September 2011 - 03:00 AM.

  • 0

#13 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 28 September 2011 - 03:02 AM

Any chance I could distribute your basic networking example with 39js? It looks great :biggrin:


Absolutely, feel free to. Please leave as much of the original code and comments in place though.
  • 0

book_forum.png


#14 Seki

Seki

    GMC Member

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

Posted 28 September 2011 - 03:03 AM

Its easy as to make a HTML5 into a Native App, to sell on App Store, for Android and iOS (Blackberry and Symbian aswell), just need the tools, ive made a few games already... xD (just testing ones for the iPhone)
  • 0


PixelJolt: Developement Blog


#15 xot

xot

    GMC Dismember

  • GMC Elder
  • 4780 posts
  • Version:GM:Studio

Posted 28 September 2011 - 03:20 AM

The difference in connection type means an HTTP request is quite a bit slower than a socket connection.


As I understand it, the point of WebSockets (and by extension Node.js with Socket.io) is that an HTTP request is required only to establish the connection. After that the connection is held open and data flows without the need for futher HTTP requests. If it is working correctly, it should be just as fast as any other netcode. I've read of latency as low as 10ms using Node.js and Socket.io. That should be adequate for anything.
  • 0
GMLscripts.com, rise from your grave!

#16 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9421 posts
  • Version:Unknown

Posted 28 September 2011 - 03:51 AM

As I understand it, the point of WebSockets (and by extension Node.js with Socket.io) is that an HTTP request is required only to establish the connection. After that the connection is held open and data flows without the need for futher HTTP requests. If it is working correctly, it should be just as fast as any other netcode. I've read of latency as low as 10ms using Node.js and Socket.io. That should be adequate for anything.

That sounds very promising, I can't wait to try out games made with this (and GM). I don't really have motivation to make my own MMORPG though.
  • 0

#17 Barling

Barling

    GMC Member

  • GMC Member
  • 127 posts

Posted 28 September 2011 - 04:08 AM

Server still isnt working i downloaded again just incase the guy updated it but nope.
  • 0

#18 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 28 September 2011 - 04:24 AM

How long ago did you download? Try now the server should be working.
  • 0

#19 Barling

Barling

    GMC Member

  • GMC Member
  • 127 posts

Posted 28 September 2011 - 05:28 AM

well now when i run the server the command line is just blank.
is something supposed to happen when I connect to the server? because my HTML5 game just shows a grey screen after I register/login.
  • 0

#20 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 28 September 2011 - 05:39 AM

Its supposed to be plank for now, I modified Socket.io as it was displaying too much terminal output but I will fix that.
Yes its supposed to say you have logged in, try again and check your javascript console (on chrome its view->Developer->Developer tools) it should say what is wrong.

You could test out my example to see what its supposed to do.
  • 0

#21 Manuel777

Manuel777

    InvaderGames

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

Posted 28 September 2011 - 11:20 AM

Would be great if you finish this.. i didnt even know socket.io existed, and it looks liike a really nice bunch of codes ;)
  • 0

#22 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 28 September 2011 - 03:57 PM

**** OMG THANK YOU MAN GOTTA SEE IF THIS WORKS
  • 0

#23 BlaXun

BlaXun

    Slime Online Creator

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

Posted 28 September 2011 - 03:58 PM

It does work. however, the server right now is (must be?) a java file....Hope this will be changed though, but I think I read that he (the creator of this) is trying it atm.
  • 0

iBNKRoX.png


#24 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 28 September 2011 - 04:33 PM

hmm still needs a lot more data types
  • 0

#25 Barling

Barling

    GMC Member

  • GMC Member
  • 127 posts

Posted 28 September 2011 - 06:27 PM

Are we able to connect this to any server?
I mean wouldn't we be able to connect it to a GM server running 39dll?
  • 0

#26 pedrosorio

pedrosorio

    GMC Member

  • GMC Member
  • 971 posts

Posted 28 September 2011 - 08:35 PM

It does work. however, the server right now is (must be?) a java file....Hope this will be changed though, but I think I read that he (the creator of this) is trying it atm.


Javascript
  • 0
"Let's leave the classics for your parents." - KC LC

#27 True Valhalla

True Valhalla

    ಠ_ಠ

  • GMC Member
  • 5277 posts
  • Version:Unknown

Posted 28 September 2011 - 10:18 PM

To run the server, will a typical web server suffice or do you need a proper server like a VPS? I suspect a VPS? The main reason I'm edging towards PHP for my game is it's not real time and I'd like to use a web server rather than my VPS to host.
  • 0

book_forum.png


#28 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 29 September 2011 - 12:47 AM

You can't directly connect to a GM server running 39dll as socket.io uses websockets and doesn't allow raw tcp connections. However i'm looking into 2 options to make this possible. 1) modifying the 39dll to use websockify which translates websockets to normal socket traffic 2) rewriting 39dll as a websocket server.
Which both would require you to use a custom dll rather than plain 39dll, option 1 would potentially allow both players from gmhtml5 and normal gm to connect to the same server, whereas number 2 wouldn't (well unless they also connected over websockets).

Currently you have to rewrite your server into javascript and run on node.js, currently i'm writing code to allow gmhtml5 servers to run in node.js, so no rewrite is required.

But I do realise that node.JS isn't ideal for everyone and will also look into a php websocket server (which will require you to write all the server code in php). But it is worth mentioning the only advantage of this is it allows you to write in php, you can't just upload to a shared hosting service and expect it to work.

Its also worth mentioning that there are Java, Go, Perl, Ruby, Erlang and Python versions of socket.io which you can already use to write servers for your gmhtml5 games.

Edited by TGMG, 29 September 2011 - 12:55 AM.

  • 0

#29 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9421 posts
  • Version:Unknown

Posted 29 September 2011 - 03:35 AM

The main reason I'm edging towards PHP for my game is it's not real time and I'd like to use a web server rather than my VPS to host.

If the game isn't real time, then the latency of an HTTP connection would probably not be noticeable. If it's turn based, then it should be fine. If it requires seeing anything in real time, like seeing other players moving around, then it would be less suitable (but can be faked in some situations).
  • 0

#30 Armisticdoom

Armisticdoom

    GMC Member

  • New Member
  • 73 posts

Posted 01 October 2011 - 04:09 PM

It would be nice if tcpaccept returned a value less than 0 if the connection failed, like 39dll.
  • 0

#31 dvdtv

dvdtv

    GMC Member

  • GMC Member
  • 39 posts

Posted 01 October 2011 - 06:06 PM

This look realy nice but i have got a problem. When i run the server.bat i see 1 line of text.
That line gives me online the place were de file stand. Then I start the proj_39jsexample en is start to play.
I changed the port to my port but that doesn't mean because I use localhost. Then I start the game
and I tried to show a message when I recieve a message but I dont recieve message from te server.

I hope you understand What I mean but my englisch isn't very well. Normaly I post on de dutch forum for game maker.

Greets,
or met vriendelijke groeten,
Dennis
  • 0

#32 FiLkAtA

FiLkAtA

    GMC Member

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

Posted 12 October 2011 - 11:46 AM

I'm trying to understand this and I hope you guys will help me out. To learn how this works I want to host the example somewhere and play around with it. I know how to host a game made with GM HTML5 but I'm confused how to host this because of the javascript server. Do I have to host it seperately and which files go where? Thanks in advance.
  • 0

#33 Smarty

Smarty

    GMC Member

  • GMC Elder
  • 7479 posts
  • Version:GM:Studio

Posted 12 October 2011 - 12:20 PM

I'm not so sure it's useful, let alone efficient, to try and enforce a 39dll syntax here, for a number of reasons. First of all you currently have no way to interface with the original 39dll socket implementation. Second, server-side code written using 39dll needs a rewrite anyway because none of what people ever wrote was using Javascript in the first place.

But the most important difference is in how 39dll and websockets treat the message part. Where 39dll tries to save pennies by concatenating binary data, websockets can only send text. By nature this is far more verbose, so the message part becomes larger in websockets than in 39dll no matter what you do. But because 39dll users expect control on the byte level, you deal with this difference in 39js by making the buffer commands push data into a text array and pulling (shifting) it out of it again. There is no difference at all in the buffer adding functions. There is no longer a point to have different functions to add different sizes of data to the buffer. There is no longer any point in making the distinction.

Edited by Smarty, 12 October 2011 - 10:17 PM.

  • 0

#34 Jolie

Jolie

    GMC Member

  • New Member
  • 105 posts

Posted 12 October 2011 - 12:39 PM

Wow, this is amazing!
This really extends the possibilities of GM HTML5!
  • 0
Hi guys!
I'm back on the English forum. I you remember me (I don't think so, I was not very active), you may remember me as a n00b. Well, I growed in experience. I make online games without any example or something, I understand surfaces and ds maps, and I learned much more about GameMaker. I'm not very good in English sometimes, so if I make a mistake, could you please say that to me?
Thanks!
My twitter account - Dutch website I made.

#35 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 12 October 2011 - 09:42 PM

Thanks for sharing.

From what I understand, websockets are turned off in Opera and Firefox for security reasons, and the only browser which it currently works on is chrome.
  • 0

Game Maker HTML5 Extensions
Mouse Extension | HTML Extension


#36 blackhawkrobbo

blackhawkrobbo

    GMC Member

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

Posted 14 October 2011 - 03:58 PM

Wow. Simply: Wow!

This solves SO many problems!
I'll finally be able to:

Run the server program on a remote desktop
Run the server program in the background WITHOUT alarms messing up
RUN THE SERVER ON A LINUX MACHINE

Oh my god! Thank you soooo freaking much! This is REALLY awesome!
  • 0

#37 Fireball16

Fireball16

    Indie Developer

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

Posted 15 October 2011 - 03:37 PM

I am just wondering, can you have a .exe with the .39dll and connect it to a html5 server using the 39js?

So can you host a server on a webpage and have exe's connect to it? :ninja:
  • 0

twitter128x12832.pngbrowser128x12832.pngandroid128x12832.pngskype128x12832.png


#38 blackhawkrobbo

blackhawkrobbo

    GMC Member

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

Posted 16 October 2011 - 03:50 PM

I am just wondering, can you have a .exe with the .39dll and connect it to a html5 server using the 39js?

So can you host a server on a webpage and have exe's connect to it? :ninja:


:whistle:

You can't directly connect to a GM server running 39dll as socket.io uses websockets and doesn't allow raw tcp connections. However i'm looking into 2 options to make this possible. 1) modifying the 39dll to use websockify which translates websockets to normal socket traffic 2) rewriting 39dll as a websocket server.
Which both would require you to use a custom dll rather than plain 39dll, option 1 would potentially allow both players from gmhtml5 and normal gm to connect to the same server, whereas number 2 wouldn't (well unless they also connected over websockets).

Currently you have to rewrite your server into javascript and run on node.js, currently i'm writing code to allow gmhtml5 servers to run in node.js, so no rewrite is required.

But I do realise that node.JS isn't ideal for everyone and will also look into a php websocket server (which will require you to write all the server code in php). But it is worth mentioning the only advantage of this is it allows you to write in php, you can't just upload to a shared hosting service and expect it to work.

Its also worth mentioning that there are Java, Go, Perl, Ruby, Erlang and Python versions of socket.io which you can already use to write servers for your gmhtml5 games.


  • 0

#39 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 17 October 2011 - 12:26 AM

"Chrome dev build 15.0.874.0 supports binary data and close reason and code."
  • 0

Game Maker HTML5 Extensions
Mouse Extension | HTML Extension


#40 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 31 October 2011 - 11:38 AM

I think you can use websockify to "translate" websocket traffic to winsocket normal traffic. Only you need to port it to win32 and I think youll be able to use it with 39dll or selfmade server on real programming language. Now I personally working on it. If I made some progress I'll post here. Good luck.
  • 0

#41 Crhonos

Crhonos

    GMC Member

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

Posted 20 November 2011 - 04:36 PM

So i can't use my c++ 39 lib baseed server ?Then it's wothless call this a 39js, if it use diferents socket programming, and does not match with the 39dll things.

I don't know if this is the same thing as you guys done here but once i saw this code here in gmc:

import java.io.File;

import pl.org.shocker.lib39dll.*;

public class Main {
        public static void main(String[] args) {
                Lib39dll.libInit();
                
                try {
                        System.out.println(Lib39dll.myHost());
                        System.out.println(Lib39dll.myMAC());
                        
                        File file = new File("asdf.dat");
                        if (file.exists()) {
                                LibFile f = LibFile.open(file,EFileMode.Read);
                                Buffer.def.clear();
                                f.read();
                                f.close();
                                
                                System.out.println(Buffer.def.readString());
                                System.out.println(Buffer.def.readUInt());
                        } else {
                                Buffer.def.clear();
                                Buffer.def.writeString("lolzord");
                                Buffer.def.writeUInt(666);
                                
                                LibFile f = LibFile.open(file,EFileMode.Write);
                                f.write();
                                f.close();
                        }
                } catch (Lib39dllException e) {e.printStackTrace();}
                
                Lib39dll.libDeinit();
        }
}
It cames with other two files: http://ifile.it/m0vkh94
Also i think that is java, and not java script, anyway, i don't know the diference.


Can anyone tell me if it's the same thing , or if this one works with the original 39dll servers and whatevers ?

Also i get this error when trying to run the example java script server:
Posted Image

You could call this Web Socket Extension, and not 39js, this way you are going to stop making people gain false hope, of programming using 39dll server(in any language that 39dll works), and this extension for gml

I was also noticing, this 39js, does not work when running the game as exe, windows mode, do it ?
Also, sorry if i was rude, i got really disappointed as i was reading the posts.


Edit: I found that on google: http://www.ostrosoft..._javascript.asp
Doesn't know if this is what we want though.
Edit2: Found this one too: http://code.google.c...s/tutorial.html

Edit3:I was thinking, you could use a js server to receive the messages, and pass then as arguments to a C++ server or a Game Maker Server.This way i think, the server would not have to be changed at all.

Edited by Crhonos, 21 November 2011 - 06:22 PM.

  • 0

#42 lukeescude

lukeescude

    GMC Member

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

Posted 25 November 2011 - 12:11 AM

Good work!

It would be nice to be able to program a server that could accept both HTML5 web socket connections and application TCP connections at the same time.

Edited by lukeescude, 25 November 2011 - 12:16 AM.

  • 0
My 39dll Tutorial
GMechanism, a Game Maker extension for Online Highscores, Achievements, Chat Engine, INI Host, etc.
Posted Image

#43 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 25 November 2011 - 12:27 AM

Why not make it use JSON? It would be so much easier for everyone, and wouldn't need 39dll's horrible functions.
  • 0

#44 Crhonos

Crhonos

    GMC Member

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

Posted 26 November 2011 - 10:25 PM

39dll is the fastest one, thats why.
  • 0

#45 Manuel777

Manuel777

    InvaderGames

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

Posted 30 November 2011 - 04:17 AM

39dll is the fastest one, thats why.

U sure? :huh:

Edited by manuel777, 30 November 2011 - 04:17 AM.

  • 0

#46 Demion

Demion

    GMC Member

  • GMC Member
  • 46 posts

Posted 02 December 2011 - 02:35 AM

del

Edited by Demion, 08 December 2011 - 10:37 PM.

  • 0

#47 john316

john316

    GMC Member

  • GMC Member
  • 21 posts

Posted 12 December 2011 - 02:17 AM

Does anybody know how i can implement this into a javascript multiplayer engine?or where to start?
  • 0

#48 blackhawkrobbo

blackhawkrobbo

    GMC Member

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

Posted 26 December 2011 - 05:03 PM

@ kaibil:
You're just to dumb to understand it.

So, at TGMG: Thanks a lot for this. i've managed to make an online MMORPG with this and its still in development. There's still something i wonder - do you know when the client sends a 'disconnect' message? because it never seems to do so.
Also the client stops functionating when you lose focus from the game. For me, this is a problem:

Game starts, connects to server
Server keeps track of ping (reset to 0 every time he receives a message)
Client keeps track of ping as well (reset to 0 every time he receives a message)
Now when the client loses foces, the game pauses, and no more messages are sent -> Server logs out the player, deletes the player instance from the array.
->>Here's my problem: The socket doesn't get deleted. This means that whenever the client gets its focus back it sends messages and the server doesn't know what to do, since the player array is gone.
I've tried:
io.sockets.disconnect(global.player[player].tcp);
//Doesn't work (no disconnect method found)

gmsocketio_disconnect(global.player[player].tcp);
//Doens't do anything ( ? )

io.sockets.clients[global.player[player].tcp]._onDisconnect();
//Doesn't work (no disconnect method found)

So what i need to do: how can i close the socket on the server? This way the client will also see that he isn't receiving messages anymore and disconnect as well. Or maybe i can send a message that he has to disconnect? Is this possible and how can i accomplish this?

By the way - i've also seen this piece of code:
io.sockets.on('disconnected', function(socket) { // basically the tcpaccept function
		console.log("DISCONNECTED");
	});
But it never gets called. How come? And how can i force the disconnect status for a client?

Thanks in advance!

Edited by blackhawkrobbo, 26 December 2011 - 05:04 PM.

  • 0

#49 kaibil

kaibil

    GMC Member

  • GMC Member
  • 119 posts
  • Version:GM8

Posted 26 December 2011 - 10:06 PM

@ kaibil:
You're just to dumb to understand it.

So, at TGMG: Thanks a lot for this. i've managed to make an online MMORPG with this and its still in development. There's still something i wonder - do you know when the client sends a 'disconnect' message? because it never seems to do so.
Also the client stops functionating when you lose focus from the game. For me, this is a problem:

Game starts, connects to server
Server keeps track of ping (reset to 0 every time he receives a message)
Client keeps track of ping as well (reset to 0 every time he receives a message)
Now when the client loses foces, the game pauses, and no more messages are sent -> Server logs out the player, deletes the player instance from the array.
->>Here's my problem: The socket doesn't get deleted. This means that whenever the client gets its focus back it sends messages and the server doesn't know what to do, since the player array is gone.
I've tried:

io.sockets.disconnect(global.player[player].tcp);
//Doesn't work (no disconnect method found)

gmsocketio_disconnect(global.player[player].tcp);
//Doens't do anything ( ? )

io.sockets.clients[global.player[player].tcp]._onDisconnect();
//Doesn't work (no disconnect method found)

So what i need to do: how can i close the socket on the server? This way the client will also see that he isn't receiving messages anymore and disconnect as well. Or maybe i can send a message that he has to disconnect? Is this possible and how can i accomplish this?

By the way - i've also seen this piece of code:
io.sockets.on('disconnected', function(socket) { // basically the tcpaccept function
		console.log("DISCONNECTED");
	});
But it never gets called. How come? And how can i force the disconnect status for a client?

Thanks in advance!



And your too much of prick to explain it.
  • 0

#50 blackhawkrobbo

blackhawkrobbo

    GMC Member

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

Posted 26 December 2011 - 11:35 PM


@ kaibil:
You're just to dumb to understand it.
.....



And your too much of prick to explain it.


True. What do you want me to explain? The whole basics of a multiplayer game are in here. Joining, seeing each other, a working server... What more do you need? A complete, ready-to-go game that you can change?

Why not ask WHAT you need and WHY and maybe then i won't be a prick and explain it to you.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users