Skip to content

krlosflipdev/multiplayer-websocket-server-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node WebSocket Server (To use with Unity multiplayer game)

This is an example of a Websocket server that uses a local database to keep all the clients updated with the information since the first player is connected.

This WebSocket server is working with Unity clients on multiplayer-websocket-client-unity.

Installing

npm install

Message Data Structure

When player connects

{
  "action": "connected",
  "data": {
    "username": "jsConnection"
  }
}

Sending player position and rotation in realtime

{
  "action": "movement",
  "data": {
    "position": {
      "x": 1,
      "y": 2,
      "z": 3
    },
    "rotation": {
      "x": 4,
      "y": 5,
      "z": 6
    }
  }
}

Run

#Install nodemon -- npm install -g nodemon --
nodemon index.js

Test

You can also test with WSCat in multiple consoles

Connect to socket server

wscat -c ws://localhost:8080

Send message

#When wscat is connected
#Connection
> { "action": "connected", "data": { "username": "jsConnection" } }

#Sending position and rotation
> {"action":"movement","data":{"position":{"x":1,"y":2,"z":3},"rotation":{"x":4,"y":5,"z":6}}}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published