# Connected callback action not working

**URL:** <https://forum.heroiclabs.com/t/connected-callback-action-not-working/3519>\
**Category:** Client Libraries\
**Tags:** getting-started, sdk-unity\
**Created:** [February 17, 2023, 9:11am UTC](https://forum.heroiclabs.com/t/connected-callback-action-not-working/3519 "2023-02-17T09:11:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven060594](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/steven060594/32/1528_2.png) [@steven060594](https://forum.heroiclabs.com/u/steven060594)\
**Post date:** [February 17, 2023, 9:11am UTC](https://forum.heroiclabs.com/t/connected-callback-action-not-working/3519/1 "2023-02-17T09:11:04Z")

</div>

# Problem

I registered a method on ‘ISocket.Connected’ to register the server connection completion callback, but the result was not as I expected. The callback was called, but ‘ISocket.IsConnected’ returned false. Why ‘ISocket.Connected’ not working? The callback to ‘ISocket.Closed’ works fine.

My unity editor version is 2020.3.25f1, and nakama sdk imported the latest version from unity asset store.

# Code

```cs
private async UniTask ConnectAsync()
        {
            string authToken = PlayerPrefs.GetString("nakama.session");

            if (!string.IsNullOrWhiteSpace(authToken))
            {
                ISession session = Nakama.Session.Restore(authToken);

                if (!session.IsExpired)
                {
                    _session = session;
                }
            }

            if (_session == null)
            {
                string deviceId;

                if (PlayerPrefs.HasKey("nakama.deviceUniqueIdentifier"))
                {
                    deviceId = PlayerPrefs.GetString("nakama.deviceUniqueIdentifier");
                }
                else
                {
                    deviceId = SystemInfo.deviceUniqueIdentifier;

                    if (deviceId == SystemInfo.unsupportedIdentifier)
                    {
                        deviceId = System.Guid.NewGuid().ToString();
                    }

                    PlayerPrefs.SetString("nakama.deviceUniqueIdentifier", deviceId);
                }

                _session = await _client.AuthenticateDeviceAsync(deviceId);

                PlayerPrefs.SetString("nakama.session", _session.AuthToken);
            }

            _socket = _client.NewSocket();

            //Register
            _socket.Connected += DoWhenConnected;
            _socket.Closed += DoWhenDisconnected;

            await _socket.ConnectAsync(_session);
        }

        //connected callback
        private void DoWhenConnected()
        {
            Debug.Log("Nakama server connecting?: " + _socket.IsConnecting);
            Debug.Log("Nakama server already connected?: " + _socket.IsConnected);
        }

        private void DoWhenDisconnected()
        {
            Debug.Log("Nakama server disconnected?" + !_socket.IsConnected);
        }

```

# Unity Console

 ![image](https://us1.discourse-cdn.com/flex020/uploads/heroiclabs/original/2X/3/30a78f7042d3871df24426ae2cedb4409fca7588.png)

---

<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:** [February 17, 2023, 5:48pm UTC](https://forum.heroiclabs.com/t/connected-callback-action-not-working/3519/2 "2023-02-17T17:48:07Z")

</div>

Hey @steven060594 this is a bug in the .NET client. Could you file an issue on the Github? `IsConnected` is set immediately after the `Connected` callback fires.

> **[Issues · heroiclabs/nakama-dotnet](https://github.com/heroiclabs/nakama-dotnet/issues)**
>
> .NET client for Nakama server written in C#. Contribute to heroiclabs/nakama-dotnet development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![steven060594](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/steven060594/32/1528_2.png) [@steven060594](https://forum.heroiclabs.com/u/steven060594)\
**Post date:** [February 18, 2023, 6:22am UTC](https://forum.heroiclabs.com/t/connected-callback-action-not-working/3519/3 "2023-02-18T06:22:38Z")

</div>

@lugehorsam , Just saw this issue you’ve already filed on Github. Thanks for your help!
