Skip to content

Instantly share code, notes, and snippets.

@danaabs
Created April 7, 2017 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danaabs/b7fc9b0cccbd55093fb6dff2c6107171 to your computer and use it in GitHub Desktop.
Save danaabs/b7fc9b0cccbd55093fb6dff2c6107171 to your computer and use it in GitHub Desktop.
Server.js
var http = require('http');
var express = require('express');
var osc = require('node-osc');
var app = express();
var client = new osc.Client('172.30.5.93', 8080);
var data = {};
//+++++++++++++++++++++++++++++++++++++++++
// client.send('6', function(){
// console.log("Sent to MAX");
// //client.kill();
// });
//++++++++++++++++++++++++++++++++++++++++
var server = http.createServer(app);
// Pass a http.Server instance to the listen method
var io = require('socket.io').listen(server);
//console.log("Server is running and waiting8080");
server.listen(8080);
// Register the index route of your app that returns the HTML file
app.get('/', function (req, res) {
console.log("Homepage");
res.sendFile(__dirname + '/index.html');
});
// Expose the node_modules folder as static resources (to access socket.io.js in the browser)
//app.use('/static', express.static('node_modules'));
// WebSocket Portion
// WebSockets work with the HTTP server
// Handle connection
io.on('connection', function (socket) {
console.log("Connected succesfully to the socket ...");
var news = [
{ title: 'My Fucking Sweet Site',date:'Today'},
];
// Send news on the socket
// socket.emit('news', news);
socket.on('newmessage', function(bone) {
console.log('new messages receive')
res=bone.split(",");
v1=res[0][0];
v2=parseFloat((res[0].split('['))[1]);
v3=parseFloat(res[1]);
v4=parseFloat((res[2].split(']'))[0]);
emit = v1;
// console.log("v1"+v1);
// console.log("v2"+v2);
// console.log("v3"+v3);
// console.log("v4"+v4);
console.log(bone);
//socket.emit('newmessage', v1);
//won't work if no info sending
// var client = new osc.Client('172.16.244.110', 8080);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
client.send(v4, function(){
console.log("Sent to MAX");
//client.kill();
});
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
});
// socket.on('disconnect', function() {
// console.log("Client has disconnected");
// });
});
@danaabs
Copy link
Author

danaabs commented Apr 7, 2017

I'm not getting any console logged confirmation that the function(bone) is working.
I can successfully connect to the socket and open the homepage, but that's it.

@juniorxsound
Copy link

juniorxsound commented Apr 8, 2017

Hi a couple of notes:
Don't use the word client, as socket has a bunch of predefined variables in the socket object coming back into the scope that uses similar name, use something distinct like OSCclient
Secondly, who is responsible for 'newmessage'? the Android device? to debug that I would probably create a 'test' socket message that get's sent from the Android with a number like 1, and then see if that is coming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment