Closed sametaylak closed 7 years ago
Hi,
You have parse error, try to like this :
io.on('connection', function (socket) { io.sockets.emit('hey', 'hey i'm sent from server');
Also you can check this http://www.kodrella.com/nodejssocket-io-ile-basit-bir-chat-uygulamasi-yapalim/ ,
2016-02-05 9:28 GMT+02:00 Samet Aylak notifications@github.com:
Hey guys i'm trying to basic socketio communication and i got a error as u see Please share your solutions :) and i'm newbie so i copy paste codes please ignore them :)
This is my serverjs
var socket = require( 'socketio' ); var express = require('express'); var app = express(); var server = require('http')createServer(app); var io = socketlisten( server ); var port = 3000; serverlisten(port, function () { consolelog('Server listening at port %d', port); }); ioon('connection', function (socket) { iosocketsemit('hey', 'hey i'm sent from server'); });
This is my indexhtml
var socket = ioconnect('http://localhost:3000'); socketon('hey', function(data){ consolelog(data); });
And this is my file structure
- public_html
- node_modules
- indexhtml
- serverjs
— Reply to this email directly or view it on GitHub https://github.com/socketio/socket.io/issues/2431.
Teşekkürler mehmetalp.com.tr http://mehmetalp.com.tr
i checked that site and i change my codes, it's running on localhost but when i upload host from ftp it's still getting same error :/
What is your error? Have you nodejs on your server? Should be change localhost to yourhost.com, also the port should be available.
2016-02-05 9:53 GMT+02:00 Samet Aylak notifications@github.com:
i checked that site and i change my codes, it's running on localhost but when i upload host from ftp it's still getting same error :/
— Reply to this email directly or view it on GitHub https://github.com/socketio/socket.io/issues/2431#issuecomment-180241550 .
Teşekkürler mehmetalp.com.tr http://mehmetalp.com.tr
That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).
i have the same error. i tried hosting it using my own laptop. it works when i access the site (on my laptop, or on other laptop/devices connected to my localnetwork) using my public ip. but when others (from outside my localnetwork) access the site, the client's connection refuses.. i am not sure what could be the problem. i was hoping that someone came up with a better solution. but to my failure, i found nothing. =(
@vainell Can you show your socket.io-client config ?
If you try to access with public IP, make sure you config socket.io-client with this public ip too.
For example:
You public IP is 192.168.2.77
and you server is listening at port 8080
Your socket.io-client config should be var socket = io('http://192.168.2.77:8080');
@dhiefphams, thank you for your response, but i already solved my issue.. I just forgot to host the port which my server and client's are using. thats why im getting a response error.. But it now works.. again, thank you!
hi @vainell i have the same problem. what did you mean by saying "I just forgot to host the port which my server and client's are using". I didn't get you saying host the port.
I was hosting it using my own pc. i forgot to indicate the port
On Sat, 2 Nov 2019, 4:02 AM PiroozMB notifications@github.com wrote:
hi @vainell https://github.com/vainell i have the same problem. what did you mean by saying "I just forgot to host the port which my server and client's are using". I didn't get you saying host the port.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/socketio/socket.io/issues/2431?email_source=notifications&email_token=AGEWYYPFJ3XGRMV2BC2RELDQRSDMXA5CNFSM4B2QJCF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC4AKXI#issuecomment-548930909, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGEWYYOXIH7CIXPWCKOSRRDQRSDMXANCNFSM4B2QJCFQ .
Okay, so if it's working on your local machine but not on the production. It's working because you are accessing your local network from your machine.
Here's the fix.
const httpServer = require('http').createServer();
const app = require('./app');
const ENV = process.env.NODE_ENV || 'development';
global.io = require('socket.io').listen(httpServer);
httpServer.listen(3002, 'PRODUCTION-URL-HERE', () => {
console.info(`Socket server started on ${PRODUCTION-URL-HERE}:${3002} (${ENV})`);
});
const src = app;
module.exports = src;
And the frontend:
componentDidMount() {
let socket = io('PRODUCTION-URL-HERE');
socket.on('notification', data => {
this.setState({
notifications: data
})
})
}
hello
anyone?
@Notekey hi! You are commenting on an old issue, please open a new issue with all necessary details. Thanks!
Please also check our tutorial: https://socket.io/docs/v4/tutorial/introduction
Hey guys i'm trying to basic socket.io communication and i got a error as u see. Please share your solutions :) and i'm newbie so i copy paste codes please ignore them :)
This is my server.js
This is my index.html
And this is my file structure