Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Create server code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomthecarrot committed Mar 14, 2018
1 parent a1a4d35 commit d2427ba
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions AR-Stopmotion-Camera/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

// Load WebSocket networking library
WebSocket = require('ws');

// Start WebSocket server
wss = new WebSocket.Server({
port: 8080,
host : '0.0.0.0'
});

cameraSocket = null;

// Configure WebSocket server
wss.on('connection', function connection(socket) {

console.log("A client connected!");

// Handle client data
socket.on('message', function incoming(message) {
console.log("Received message: %s", message);
if (message == "camera") {
cameraSocket = socket;
}
else {
if (cameraSocket != null) {
cameraSocket.send("photo\n");
}
}
});

// Handle client disconnect
wss.on('close', function close() {
console.log("A client disconnected");
});

// Handle client error
wss.on('error', function() {
console.log("A connection error occurred");
});

});

0 comments on commit d2427ba

Please sign in to comment.