express, socket.io server for browser client and node.js client
NickName:CiscoKidx Ask DateTime:2015-07-30T09:03:10

express, socket.io server for browser client and node.js client

I am trying to set-up an express server with socket.io that will allow node.js clients and browser clients to connect. The browser connects with no problem. The node.js client using socket.io-client give an error: unhandled socket.io url

Server:

var express = require('express'),
    io = require('socket.io');

var app = express();
var host = 'localhost';
var port = process.env.PORT || 8080;

var server = app.listen(port, function() {
    console.log('Gulp is starting my app on PORT: ' + port)
});
io = io.listen(server);

app.use('/', express.static(__dirname + '/'));

io.on("connection", function(socket) {

    socket.on('clientMessage', function(jsonData, from) {
        socket.emit('serverMessage', 'Got a message!');
        console.log('Data being sent from', from, 'is:\n' + jsonData);
    });
});

Client:

var io = require('socket.io-client')

var socket = io.connect('http://192.168.1.222:8080', {reconnect: true});

socket.emit('clientMessage', 'Hello', 'Pi-Voyager');

Copyright Notice:Content Author:「CiscoKidx」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31713620/express-socket-io-server-for-browser-client-and-node-js-client

More about “express, socket.io server for browser client and node.js client” related questions

express, socket.io server for browser client and node.js client

I am trying to set-up an express server with socket.io that will allow node.js clients and browser clients to connect. The browser connects with no problem. The node.js client using socket.io-clien...

Show Detail

Connecting NodeMCU Lua socket client with node.js socket.io server

I want to connect a NodeMCU Lua socket client to node.js socket.io server. NodeMCU Lua code: sk = net.createConnection(net.TCP, 0) sk:on("receive", function ( sck,c ) print (c) end) sk:on("

Show Detail

Flutter socket.io client not connecting with node.js socket.io server via https

I am trying to connect flutter socket.io client to node.js socket.io client via https, but that is not happening. Via browser I am able to establish connection and also using http in mobile, but fo...

Show Detail

https handshake fails from JavaScript client to Node.js/socket.io server

I'm able to handshake from a JavaScript client (NOT browser or Node.js based) to a Node.js server that uses socket.io using http but not https. For https, the server code includes var app = expres...

Show Detail

Socket.io-client simple client/server test wont connect - Node.js

I am trying to get some simple communication to work in Node.js using socket.io and socket.io-client. I have two scripts, server.js and client.js. The server.js script can bind to a webfacing por...

Show Detail

cannot get client server running using express in node.js

hey i just started tinkering with node.js and am a complete noob. i am trying to get a simple client server communication going using socket.io and express (i have never used these before). here i...

Show Detail

socket.emit from node.js client to browser client

I am trying to emit a message from the node.js client to the web client. I am assuming this must be done through the server. Any help is appreciated. The erorr I see in the browser is: GET http:/...

Show Detail

How to debug a simulated browser client of socket.io in node.js server

I have simulated a browser client of socket.io in the node.js server I am creating the simulated browser client when particular message arrived from a Real browser client. console.log('cre...

Show Detail

How to debug a simulated browser client of socket.io in node.js server

I have simulated a browser client of socket.io in the node.js server I am creating the simulated browser client when particular message arrived from a Real browser client. console.log('cre...

Show Detail

socket.io common server and client code

I'm trying to build an app with node.js, socket.io and express. I have a public directory which contains all the client code and that is sent to client via express app.use(express.static(__dirna...

Show Detail