Forum Multiplayer [Solved] Server not receiving messages

Discussion and help relating to the PlayerIO Multiplayer API.

[Solved] Server not receiving messages

Postby icepegasus » June 9th, 2018, 9:01 pm

So I have my server which is tiny right now, since I've just started:
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PlayerIO.GameLibrary;

namespace BingoServer
{
    class LobbyPlayer : BasePlayer
    {

    }
    [RoomType("Lobby1")]
    class lobby : Game<LobbyPlayer>
    {
        public override void GameStarted()
        {
            PreloadPlayerObjects = true;
        }
        public override void GotMessage(LobbyPlayer pl, Message m)
        {
            if (m.Type == "init")
            {
                pl.Send("init");
                PlayerIO.BigDB.LoadOrCreate("Config", "Game", delegate (DatabaseObject dataObj)
                {
                    dataObj.Set("test", true);
                    dataObj.Save();
                });
            }
            else
            {
                pl.Send("wm");
            }
        }
    }
}


and this is the code for connecting to the server (in c#, my game is "multiplayer bingo" in windows forms application.)
Code: Select all
void handlemsg(object sender, PlayerIOClient.Message m)
        {
            switch(m.Type)
            {
                case "init":
                    MessageBox.Show("Connected!");
                    break;
                default:
                    MessageBox.Show("Received unknown msg");
                    break;
            }
        }
        void connection()
        {
            try
            {
                client = PlayerIO.QuickConnect.SimpleConnect(gameId, Email, Pass, null);
                client.Multiplayer.CreateJoinRoom("Lobby1", "Lobby1", true, null, null, delegate (Connection conn)
                {
                    MessageBox.Show("reached 1");
                    con = conn;
                    conn.Send("init");
                    conn.OnMessage += new MessageReceivedEventHandler(handlemsg);
                    //conn.OnDisconnect += new DisconnectEventHandler(onDisconnect);
                }, delegate (PlayerIOError error)
                {
                    MessageBox.Show(error.Message);
                });
            }
            catch(PlayerIOError r)
            {
                MessageBox.Show(r.ToString());
            }
        }


but when I connect to the game, It shows I am online, but it doesn't receive the "init" message.
anyone knows what to do?


Edit:
Problem solved. Apparently playerIO doesn't support .net framework 4.6.1?
Version 4.5.2 works fine.
Last edited by icepegasus on June 10th, 2018, 4:53 pm, edited 2 times in total.
icepegasus
Paid Member
 
Posts: 2
Joined: December 19th, 2017, 2:41 pm

Re: Server not receiving messages

Postby realmaster42 » June 10th, 2018, 1:26 pm

I'd suggest moving the OnMessage to before you send init.

If the latency isn't too big, you are going to recieve init back before you initialized the message reciever.
realmaster42
 
Posts: 10
Joined: April 7th, 2014, 6:38 pm

Re: Server not receiving messages

Postby icepegasus » June 10th, 2018, 1:48 pm

If that'd be the case, "test" in the config table would still be turned to true though, but it stays false

edit:
I also trying switching between them and it still doesn't work D:
icepegasus
Paid Member
 
Posts: 2
Joined: December 19th, 2017, 2:41 pm

Re: [Solved] Server not receiving messages

Postby Henrik » June 12th, 2018, 2:07 am

Hey icepegasus,

That it works in one version of .Net but not another is super strange, but from looking at your code I suspect there's some kind of race condition going on. You're sending a message to the server, which then immediately send a message back, and you're setting up your message handlers after you've sent your message. That means there's a possibility that your client receives the response from the server before there are any message handlers to handle it. And if you see a difference between two minor versions of .Net, I'm guessing there's some kind of internal network handling queuing locking whatever that moves the probability one way or the other.

Try running the development server in debug mode, put a breakpoint right before it sends back "init" to the client, and see what happens when you start the client.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to Multiplayer



cron