Migrating from socket.io 0.9.x to 1.4.x - can't get socket.io to start

Zuzuesque

I am in the process of updating an old application to use socket.io 1.4 instead of 0.9 (and express 4 instead of 3) but I am unable to get socket.io to start up. In my old app I would set up things as follows:

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

var app = express();
var server = http.createServer(app);

var io = socket.listen(server);
server.listen(8080);

According to the 1.x docs I thought this should work:

var express = require('express');
var http = require('http');

var app = express();
var server = http.createServer(app);

var io = require('socket.io')(server);
server.listen(8080);

I can't figure out what I am missing. Tried to add io.listen(server) as well in case passing the server wasn't enough, but that has no effect either. I don't think it is the syntax which is wrong... but I am obviously missing some step to get this working as before.

jfriend00

I'll try to supply a useful answer here so you can close up the question.

Your second block of code is completely consistent with this combination shown in the socket.io doc. The only difference is that they use the .Server() constructor and you use the .createServer() method which (if you look at the code) do the same thing:

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(8080);

So, I don't think this is where the issue is. Some things to check:

  1. Are there any startup errors showing in the node console?
  2. How do you know that socket.io is not started? One difference in the post 1.0 world is that the socket.io server code does not output anything to the console when it starts like it did on the 0.9x world. This has confused many.
  3. If you still have issues, please show the corresponding client code.

Edit: As the OP discovered in comments when investigating some other things I asked, the socket.io server was starting just fine - the OP was just expecting to see some console output that used to be there before the 1.x version.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

socket io get id of the disconnected socket

분류에서Dev

使用WebSocket手动连接到socket.io 1.x,进行容量测试

분류에서Dev

socket.io don't send data

분류에서Dev

JavaScriptCore + Socket.IO

분류에서Dev

돛 0.10.x에 websockets (socket.io) 사용

분류에서Dev

Socket.IO 1.4.x의 전송 설정

분류에서Dev

Android 개발, Gottox socket.io-java-client : file not fount Exception /socket.io/1/

분류에서Dev

socket.io/1/?t=1437482662157404 찾을 수 없음

분류에서Dev

Express with Socket.IO: Server doesn't receive emits from client

분류에서Dev

Express 4로 Socket.io 모듈화

분류에서Dev

Loop through all sockets in socket.io v1

분류에서Dev

Scaling socket.io broadcast

분류에서Dev

Sending pm with Socket.IO

분류에서Dev

Heroku의 Socket.io

분류에서Dev

dedicated servers for socket.io?

분류에서Dev

High Latencies In Socket.IO

분류에서Dev

Node JS Socket.io

분류에서Dev

Socket.IO on client side

분류에서Dev

NodeJS + Socket.IO + Mysql

분류에서Dev

Can I use rooms in namespaces in socket.io

분류에서Dev

socket.io 0.9.x에서 1.4.x로 마이그레이션-socket.io를 시작할 수 없습니다.

분류에서Dev

1.0.x를 지원하는 Socket.io Java 클라이언트

분류에서Dev

Android socket.io 2 클라이언트에서 node.js socket.io 3.x 서버에 연결할 수 없습니다.

분류에서Dev

Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1

분류에서Dev

Android MediaPlayer java.io.IOException : 준비 실패. : 상태 = 0x1

분류에서Dev

Socket.io 1.x + Express (http 사용) : 특정 클라이언트 ID로 메시지를 보내는 방법은 무엇입니까?

분류에서Dev

Socket.io IE7-9 JSONP 폴링 오류

분류에서Dev

socket.io-socket.on 약속 대기

분류에서Dev

java.io.IOException : 유효하지 않은 헤더 서명; 0x6D78204C4D54483C 읽기, 0xE11AB1A1E011CFD0 예상

Related 관련 기사

  1. 1

    socket io get id of the disconnected socket

  2. 2

    使用WebSocket手动连接到socket.io 1.x,进行容量测试

  3. 3

    socket.io don't send data

  4. 4

    JavaScriptCore + Socket.IO

  5. 5

    돛 0.10.x에 websockets (socket.io) 사용

  6. 6

    Socket.IO 1.4.x의 전송 설정

  7. 7

    Android 개발, Gottox socket.io-java-client : file not fount Exception /socket.io/1/

  8. 8

    socket.io/1/?t=1437482662157404 찾을 수 없음

  9. 9

    Express with Socket.IO: Server doesn't receive emits from client

  10. 10

    Express 4로 Socket.io 모듈화

  11. 11

    Loop through all sockets in socket.io v1

  12. 12

    Scaling socket.io broadcast

  13. 13

    Sending pm with Socket.IO

  14. 14

    Heroku의 Socket.io

  15. 15

    dedicated servers for socket.io?

  16. 16

    High Latencies In Socket.IO

  17. 17

    Node JS Socket.io

  18. 18

    Socket.IO on client side

  19. 19

    NodeJS + Socket.IO + Mysql

  20. 20

    Can I use rooms in namespaces in socket.io

  21. 21

    socket.io 0.9.x에서 1.4.x로 마이그레이션-socket.io를 시작할 수 없습니다.

  22. 22

    1.0.x를 지원하는 Socket.io Java 클라이언트

  23. 23

    Android socket.io 2 클라이언트에서 node.js socket.io 3.x 서버에 연결할 수 없습니다.

  24. 24

    Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1

  25. 25

    Android MediaPlayer java.io.IOException : 준비 실패. : 상태 = 0x1

  26. 26

    Socket.io 1.x + Express (http 사용) : 특정 클라이언트 ID로 메시지를 보내는 방법은 무엇입니까?

  27. 27

    Socket.io IE7-9 JSONP 폴링 오류

  28. 28

    socket.io-socket.on 약속 대기

  29. 29

    java.io.IOException : 유효하지 않은 헤더 서명; 0x6D78204C4D54483C 읽기, 0xE11AB1A1E011CFD0 예상

뜨겁다태그

보관