# ReceivedMatchState is not Receiving anything

**URL:** <https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972>\
**Category:** Local Setup\
**Tags:** getting-started, server-framework\
**Created:** [September 16, 2020, 8:55pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972 "2020-09-16T20:55:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 16, 2020, 8:55pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/1 "2020-09-16T20:55:09Z")

</div>

i have this code

```auto
// Use whatever decoder for your message contents.
        var enc = System.Text.Encoding.UTF8;
        _socket.ReceivedMatchState += newState =>
        {
            var contentmsg = enc.GetString(newState.State);
            switch (newState.OpCode)
            {
                case 101:
                    Debug.LogFormat("User '{0}'' sent '{1}'", newState.UserPresence.Username, contentmsg);
                    RunOnUnityThread(() => {
                        // Do Unity stuff
                        Debug.Log("is this working ? user send message");
                        StartCoroutine(ChatNotificationProcess(newState.UserPresence.Username, contentmsg));
                    });
                    break;
                default:
                    Debug.LogFormat("User '{0}'' sent '{1}'", newState.UserPresence.Username, contentmsg);
                    RunOnUnityThread(() => {
                        // Do Unity stuff
                        Debug.Log("is this working ? user send message");
                        StartCoroutine(ChatNotificationProcess(newState.UserPresence.Username, contentmsg));
                    });
                    break;
            }
        };
var match = await _socket.JoinMatchAsync(Player.PVP.MatchID);
        foreach (var presence in match.Presences)
        {
            Debug.LogFormat("MATCH INFO : User id '{0}' name '{1}'.", presence.UserId, presence.Username);
            if (presence.Username != username)
            {
                var newState = new Dictionary<string, string> { { "chatmessage", presence.Username + " join to the Match" } }.ToJson();
                StartCoroutine(ChatNotificationProcess("Server", (string)newState));
                newState = new Dictionary<string, string> { { "chatmessage", username + " join to the Match" } }.ToJson();
                StartCoroutine(ChatNotificationProcess("Server", (string)newState));
            }
        }

```

The players join fine , but i dont know why im not receiving anything on the callback  
i have the chat message code this way

```auto
var opCode = 101;
var newState = new Dictionary<string, string> { { "chatmessage", message } }.ToJson();
await socket.SendMatchStateAsync(MatchID, opCode, newState);

```

I dont see any red error so i dont know whats going on wish some body can guide me so i can debug and see whats going on? thanks

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [September 17, 2020, 3:15pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/2 "2020-09-17T15:15:05Z")

</div>

Hey @PabloMonfort, could you wrap your async calls in a `try...catch` block in order to catch any errors arising from within the network call tasks?

---

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 18, 2020, 12:07am UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/3 "2020-09-18T00:07:24Z")

</div>

you mean something like this?

```auto
try
        {
            await socket.SendMatchStateAsync(MatchID, opCode, (string)content);
        }
        catch (Exception e)
        {
            Debug.LogFormat("Async operation threw: {0}", e.ToString());
            throw;
        }

```

? if you can give me more details would be nice , sorry my ignorance but im still not getting anything using this way :S

---

<div class="post-metadata">

**Author:** ![lugehorsam](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/lugehorsam/32/314_2.png) [@lugehorsam](https://forum.heroiclabs.com/u/lugehorsam)\
**Post date:** [September 18, 2020, 2:27am UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/4 "2020-09-18T02:27:36Z")

</div>

Yes that `try...catch` looks right.

Is `match.Presences` returning a populated collection?

---

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 18, 2020, 2:29am UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/5 "2020-09-18T02:29:50Z")

</div>

> [@PabloMonfort](#):
>
> `match.Presences`

match.Presences yes it does. but it dosnt recieve what i send with

```auto
await socket.SendMatchStateAsync(MatchID, opCode, (string)content);

```

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [September 18, 2020, 9:49am UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/6 "2020-09-18T09:49:18Z")

</div>

@PabloMonfort Are you using relayed matches, or authoritative? If you’re using relayed do not expect the message to be echoed back to you - it will only be sent to other users in the match, excluding the sender.

---

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 18, 2020, 4:53pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/7 "2020-09-18T16:53:11Z")

</div>

We are using authoritative, its created in the server side the match then users recieve the matchid from server and then both join, but im not receiving anything on here

```auto
_socket.ReceivedMatchState += newState =>
        {
var contentmsg = enc.GetString(newState.State);
            switch (newState.OpCode)
            {
                case 101:
                    Debug.LogFormat("User '{0}'' sent '{1}'", newState.UserPresence.Username, contentmsg);
                    RunOnUnityThread(() => {
                        // Do Unity stuff
                        Debug.Log("is this working ? user send message");
                        StartCoroutine(ChatNotificationProcess(newState.UserPresence.Username, contentmsg));
                    });
                    break;
                default:
                    Debug.LogFormat("User '{0}'' sent '{1}'", newState.UserPresence.Username, contentmsg);
                    RunOnUnityThread(() => {
                        // Do Unity stuff
                        Debug.Log("is this working ? user send message");
                        StartCoroutine(ChatNotificationProcess(newState.UserPresence.Username, contentmsg));
                    });
                    break;
            }
        };

```

so you understand now my problem ? coz i cant understand whats going on, even the try stuff dosnt return anything so i dont have idea whats going on or why not send messages, both users are joined , i have fix all the auth code fixed for reconnection sockets etc , but this part still is not working to me and cant understand why , any hint? thanks

Even if was the case zyro thats not the case btw, none of the two players recieve anything so i dont know what you mean with that echoed coz i cant recieve none message not even a log to understand whats going on with try catch :S

---

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 18, 2020, 7:59pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/8 "2020-09-18T19:59:59Z")

</div>

we are using the Go example , maby its coz i didnt add notifications to the player from the matchloop? or something like that? sorry im trying to understand im new to go lang

---

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 18, 2020, 10:13pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/9 "2020-09-18T22:13:44Z")

</div>

i noticed that our match loop is not broadcasting anything back, can you be too gentleman and help me to get work

```auto
func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, state interface{}, messages []runtime.MatchData) interface{} {
    return state
}

```

this my matchLoop on server , but i dont know how to send a broadcast dispatcher in go there is no example about this, there is one in lua but no in go and im kind lost on how i can send a message coz we was using rpc for other things and now i believe we need to use this match loop and avoid rpc avoid notifications too for game since we shuold handle a timer and turn based multiplayer game , i wish to can have more information to learn the Go part of this match Api of nakama and i think you guys are doing very well you should be proud of your work . any help its apprecciated thanks .

---

<div class="post-metadata">

**Author:** ![zyro](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/zyro/32/14_2.png) [@zyro](https://forum.heroiclabs.com/u/zyro)\
**Post date:** [September 19, 2020, 4:20pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/10 "2020-09-19T16:20:43Z")

</div>

@PabloMonfort Your match loop ignores all input, sends no data out, and effectively does nothing with the match state.

The [Go match runtime API](https://heroiclabs.com/docs/gameplay-multiplayer-server-multiplayer/#match-runtime-api_1) is identical to the Lua one by design. A simple example looks like this:

```auto
opCode := 0
data := []byte("{\"some\":\"data\"}")
var presences []runtime.Presence
var sender runtime.Presence
dispatcher.BroadcastMessage(opCode, data, presences, sender, true)

```

This will broadcast a message with opcode `0` and `{"some":"data"}` as a payload, to all users in the match, and with a `nil` sender.

---

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 21, 2020, 6:16pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/11 "2020-09-21T18:16:44Z")

</div>

> [@zyro](#):
>
> ```auto
> opCode := 0
> data := []byte("{\"some\":\"data\"}")
> var presences []runtime.Presence
> var sender runtime.Presence
> dispatcher.BroadcastMessage(opCode, data, presences, sender, true)
> 
> ```

ok thanks man , im going to try this but its the solution to my problem so far, thanks.

---

<div class="post-metadata">

**Author:** ![PabloMonfort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/pablomonfort/32/324_2.png) [@PabloMonfort](https://forum.heroiclabs.com/u/PabloMonfort)\
**Post date:** [September 21, 2020, 6:34pm UTC](https://forum.heroiclabs.com/t/receivedmatchstate-is-not-receiving-anything/972/12 "2020-09-21T18:34:38Z")

</div>

i confirm , your code fixed all the problems i was having with this part , very thanks zyro. so people if have same problem then me this is the way to go .
