Ceosol's Multiplayer Development

ceosol

  • *
  • Posts: 2263
Hi all,

I am attempting to create a new extension for multiplayer. I will keep you updated on my progress in this thread.

So far I was able to create a private server in c++ and connect to it in a stencyl flash test.

« Last Edit: July 22, 2015, 08:07:58 pm by ceosol »

ErLuiSS

  • Posts: 125
nice work! I'll be watching this topic :)

ceosol

  • *
  • Posts: 2263
It will be slow going. I had a course in qBASIC and a course in C++ almost 20 years ago and barely touched computers (other than microsoft office and games) since then. If I can manage to get this to work, I will definitely need assistance packaging it up into haxe :)

mdotedot

  • Posts: 1569
Hello Ceosol,

You can think about creating it in HaXe in the first place.
If you are 'only' supplying turn-based stuff you do not have to go the way of creating a dedicated server but you can use MySQL/PHP.
If you want to create an UDP real-time multiplayer route, then you indeed are on the right track to create a server. You can make it in a variaty of languages.

Good luck with it and I will follow along.

Best regards from
M.E.
Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

ceosol

  • *
  • Posts: 2263
I was trying to use cs2hx.exe to convert what I have into haxe. At least I recognize some of the c++ syntax, haxe is completely foreign to me. If anybody could recommend (or tell me how to properly use cs2hx), it would make incorporating everything really easy into stencyl.

I have game clients that can send messages to the game server now, but nothing shows up other than  a message saying that the client has sent something. I haven't looked into having flash run the client directly (again, it would be easy if I could convert into haxe).

ceosol

  • *
  • Posts: 2263
I made a quick client extension and it seemed to load alright. I need to be able to test it, though. Is there a haxe command for connecting to a server? I have tried a bunch of commands with ("localhost"):port. With those, I kept getting unexpected ( or "127. errors. The stencyl block for openurlinbrowser works for connecting, but then it actually opens a browser. When I try to replicate the stencyl block (openurlinbrowser) as custom code, it gives me error messages.

If anybody could point me in the right direction, I would be very appreciative :)

mdotedot

  • Posts: 1569
Hello Ceosol,

Probably you have been using one or more of the URLLoader / Http.hx / Loader classes. They assume HTTP protocol over TCP and you have to write the protocol behavior for them to work.

Your best bet is to implement the Client using Sockets : http://old.haxe.org/doc/neko/client_server

Hope this helps you pointing in the right direction. HaXe is much like ActionScript/JavaScript and 'easier' than C++.

Best regards from
M.E.
Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

ceosol

  • *
  • Posts: 2263
Thanks for checking it out M.E. I found that page also and tried the custom code block with:

// file Client.hx
class Client {
    static function main() {
        var s = new sys.net.Socket();
        s.connect(new sys.net.Host("localhost"),5000);
        while( true ) {
            var l = s.input.readLine();
            trace(l);
            if( l == "exit" ) {
                s.close();
                break;
            }
        }
    }
}

That was giving me unexpected class, unexpected function and unexpected (  errors. :(

mdotedot

  • Posts: 1569
* create new game
* create a click event on scene
* put Flow->advanced-> code block

Code: [Select]
   var s = new sys.net.Socket();
        s.connect(new sys.net.Host("localhost"),5000);
        while( true ) {
            var l = s.input.readLine();
            trace(l);
            if( l == "exit" ) {
                s.close();
                break;
            }
        }
 

Run native (no flash!)

Failed to connect on localhost:5000

Well there is no server on localhost:5000

Create another game
in after 1 second event flow->advanced->code block

Code: [Select]
  var s = new sys.net.Socket();
        s.bind(new sys.net.Host("localhost"),5000);
        s.listen(1);
        trace("Starting server...");
        while( true ) {
            var c : sys.net.Socket = s.accept();
            trace("Client connected...");
            c.write("hello\n");
            c.write("your IP is "+c.peer().host.toString()+"\n");
            c.write("exit");
            c.close();
        }

Run
 .. Wait for it to start

Then run the Client program you created earlier


[LOG] SceneEvents_0.hx:84: Starting server...
[LOG] SceneEvents_0.hx:87: Client connected...



Next step to make on your own: make a draw event in the client to put the text received from the server into a list and draw that list on screen....

If you put the server application on a server that is attached directly to the web (i.e. port forward 5000 to the server where the app is running) and you have a real client/server thing going on ..

Next step: Make multiple connections to the server (follow steps in the posted article)

Next step after that make logic in the client/server to communicate whatever you want to communicate

Good Luck

Best regards from
M.E.
Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

ceosol

  • *
  • Posts: 2263
I got to the server/client connection log. Thank you very much. :)

ceosol

  • *
  • Posts: 2263
I was looking over Electrotank's old kit.  Since haxe can call upon c++ for iOS and java for android, is there a reason why we cannot just use the old multiplayer scripts and call upon them in new haxe games?

SadiQ

  • Posts: 1788
Doesn´t that kit rely on some API files? If you want to integrate some external API you might as well look at playerIO since rob1221 started an extension already.
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

ceosol

  • *
  • Posts: 2263
I've learned a little bit more about haxe, so I decided to look into this again.

This custom code:

class Server{
  function new() { }

  function foo(x,y) { return x + y; }

  static function main() {
    var ctx = new haxe.remoting.Context();
    ctx.addObject("http://localhost:2000/remoting.n",new Server());
    // handle normal request
  }
}

and this custom code block in a behavior:

    var URL = "http://localhost:2000/remoting.n";
    var cnx = haxe.remoting.HttpAsyncConnection.urlConnect(URL);
    cnx.setErrorHandler( function(err) { trace("Error : "+Std.string(err)); } );
    cnx.Server.foo.call([1,2]);

...actually build in flash. I haven't figured out what the call of localhost should be, so they are not quite connecting, yet. But at least no errors in syntax. From what I have been reading, the remoting function works across platforms between flash, native and java (maybe more). People have been building multiplayer haxe games using it. One of the things they recommend is having a full build on the server side - in a cloud, as well as the client side, to make sure that the data transfer it quicker and less hackable.

mdotedot

  • Posts: 1569
Hello Ceosol,

Looks interesting. Never have worked with haxe.remoting!

Server-side programming is usually best in handling Multiplayer games.
My own approach relies more on database-connections, but that is because of my day-job experience  :)

Since I don't know about haxe.remoting I can't really help with the localhost thing, but basically you should be able to use telnet (or putty with telnet) and open the port 2000 to get a connection. Use netstat -a to find the port 2000 on the localhost.
There should be a program that is listening on the 2000 port.

Good luck with it!

Best regards from
M.E.
Hanging out in the Chat:  http://www.stencyl.com/chat/

Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

ceosol

  • *
  • Posts: 2263
Thanks for checking in M.E. I don't know how much time I will dedicate to this, but I'll update it as I go along.