# Socket connect giving error 'WebSocket is not defined'

**URL:** <https://forum.heroiclabs.com/t/socket-connect-giving-error-websocket-is-not-defined/4862>\
**Category:** Client Libraries\
**Tags:** sdk-javascript\
**Created:** [January 11, 2024, 2:10pm UTC](https://forum.heroiclabs.com/t/socket-connect-giving-error-websocket-is-not-defined/4862 "2024-01-11T14:10:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HailMaverick](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@HailMaverick](https://forum.heroiclabs.com/u/HailMaverick)\
**Post date:** [January 11, 2024, 2:10pm UTC](https://forum.heroiclabs.com/t/socket-connect-giving-error-websocket-is-not-defined/4862/1 "2024-01-11T14:10:43Z")

</div>

Hi,

I am trying to build my Bot logic in Javascript using nakama-js.

While trying to connect socket to my Nakama server, i am getting error as ‘WebSocket is not defined’.

```auto
await nSocket.connect(nSession, appearOnline); //Getting error here

```

My testing code is

```auto
const authenticate = async(deviceId) => {
    var client = new nakamaSDK.Client("defaultkey", IPAddress, port, false);
    client.timeout = 10000;
    var nSession = null;
    var nSocket = null;
    try {                
        nSession = await client.authenticateDevice(deviceId);
        nSocket = client.createSocket();
        var appearOnline = false;
        await nSocket.connect(nSession, appearOnline);        
    }
    catch (err) {
        console.log("Error authenticating device: %o:%o", err.statusCode, err.message);
    }

    return {
        'client': client,
        'session': nSession,
        'socket': nSocket
      };

};

```

Do i need to import something else ?

---

<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:** [January 11, 2024, 9:39pm UTC](https://forum.heroiclabs.com/t/socket-connect-giving-error-websocket-is-not-defined/4862/2 "2024-01-11T21:39:05Z")

</div>

Hey @HailMaverick the nakama-js library is intended for use in the browser.

For bot logic, you should use consider using our Typescript or Go server frameworks. You can find more information on our Typescript framework here:

> **[TypeScript Runtime](https://heroiclabs.com/docs/nakama/server-framework/typescript-runtime/)**
>
> Learn how to configure and develop your project using JavaScript for your game server custom logic.

This will give you better control of Nakama’s functionality by using before and after hooks and a match handler. This lends itself better to implementing bot logic.

---

<div class="post-metadata">

**Author:** ![HailMaverick](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@HailMaverick](https://forum.heroiclabs.com/u/HailMaverick)\
**Post date:** [January 12, 2024, 6:48am UTC](https://forum.heroiclabs.com/t/socket-connect-giving-error-websocket-is-not-defined/4862/3 "2024-01-12T06:48:41Z")

</div>

Hey @lugehorsam , I am using Go runtime for my game server logic. My game is kind of party game where i need 100 people in the match. I want to create bots who can act like clients and play the game in the same manner as the real user. They should also do random chats in the game room.

Should we write the bots then along with Server module ?

---

<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:** [January 12, 2024, 3:37pm UTC](https://forum.heroiclabs.com/t/socket-connect-giving-error-websocket-is-not-defined/4862/4 "2024-01-12T15:37:33Z")

</div>

Hey @HailMaverick yes I would use the Go match handler API in our server framework to handle bots rather than creating Nakama users for them, which would lead to an excessive amount of users in your database.

Using the match handler API, you can broadcast match state to real players with messages representing the bot’s actions. Each bot will implement the user presence interface and join/leave the match from within your Go match handler. You’ll implement a match loop function that handles the actual broadcasting of messages from the AI.

You can see our reference documentation for the match handler in Go here:

> **[Match Handler API](https://heroiclabs.com/docs/nakama/server-framework/go-runtime/function-reference/match-handler/)**
>
> This page lists all functions for Nakama's Server Authoritative multiplayer match handler.

You can also find an example here of using an AI (in a 1v1 context) to perform bot behaviour. In particular, see `match_handler.go` and `ai.go`:

> **[GitHub - heroiclabs/nakama-project-template: An example project on how to set...](https://github.com/heroiclabs/nakama-project-template)**
>
> An example project on how to set up and write custom server code in Nakama server. - GitHub - heroiclabs/nakama-project-template: An example project on how to set up and write custom server code in...
