gamesocket
v0.1.10
Published
NodeJS Game Server WebSocket Framework
Downloads
3
Readme
What is this?
This is a super easy to use websocket based game server and client.
Install
npm install gamesocket
Require
let GameSocket = require("gamesocket");
Game Client
Define the address to connect to and handle the events, finally connect to the server using connect().
let GS = GameSocket.client('ws://127.0.0.1:8080');
GS.on('open', (server)=>{
console.log("Connected to server.");
// Send a message to the server.
server.send({message:"Hello server."});
});
GS.on('close', (server)=>{
console.log("Connection lost to server.");
});
GS.on('error', (server, error)=>{
console.log("Error from server:", error);
});
GS.on('data', (server, data)=>{
console.log("Data retrieved:", data);
});
GS.on('send', (server, data)=>{
console.log("Data sent:", data);
});
GS.connect();
Game Server
Define the port and handle the events.
let GS = GameSocket.server(8080);
GS.on('open', (client)=>{
console.log("Connected to client.");
// Send a message back to the client giving them their remoteAddress.
client.send({message:"Hello " + client.connection.remoteAddress + "."});
});
GS.on('close', (client)=>{
console.log("Connection lost to client.");
});
GS.on('error', (client, error)=>{
console.log("Error from client:", error);
});
GS.on('data', (client, data)=>{
console.log("Data retrieved from client:", data);
});
GS.on('send', (client, data)=>{
console.log("Data sent to client:", data);
});