I installed: Node, npm socket.io and npm websockets on ubuntu. Javascrip code is below. And its running on 139.59.215.170 but unity wont get any data :( Do you have any idea what could be wrong ? Code is fine, i tested it on my computer.
#!/usr/bin/env nodejs
var io = require('socket.io')({
transports: ['websocket'],
});
var userdataN = [ ];
var redovi = 6;
for(var i = 0; i < redovi; ++i) {
userdataN[i] = [ ];
}
console.log("Online players: " + userdataN[0].length);
io.attach(4567);
io.on('connection', function(socket){
socket.on('userdata', function(data){
if(userdataN[0].indexOf(socket.id) == -1){
userdataN[0].push(socket.id);
}else{
var poz = userdataN[0].indexOf(socket.id);
userdataN[1][poz] = data.username;
userdataN[2][poz] = data.x;
userdataN[3][poz] = data.y;
userdataN[4][poz] = data.z;
userdataN[5][poz] = data.rotY;
socket.emit('update', {
username : userdataN[1],
x : userdataN[2],
y : userdataN[3],
z : userdataN[4],
rotY : userdataN[5]
});
}
})
socket.on('chatmsg', function(poruka){
var poz = userdataN[0].indexOf(socket.id);
socket.emit('update', {
username : userdataN[1][poz],
msg : poruka
});
})
socket.on('disconnect', function() {
var poz = userdataN[0].indexOf(socket.id);
userdataN[0].splice(poz,1);
userdataN[1].splice(poz,1);
userdataN[2].splice(poz,1);
userdataN[3].splice(poz,1);
userdataN[4].splice(poz,1);
userdataN[5].splice(poz,1);
})
})
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Lol, no edit button.
Just to add that im trying to connect with my unity game. ws://139.59.215.170:4567/socket.io/?EIO=4&transport=websocket
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.