SocketCluster / socketcluster-client

JavaScript client for SocketCluster
MIT License
291 stars 92 forks source link

Socket hung up error on react native android #82

Closed cogmeta closed 7 years ago

cogmeta commented 7 years ago

I know this has been posted multiple times and it is always some simple configuration mistake or version mismatch but no matter what we try, we cant seem to get rid of this error "SocketProtocolError", message: "Socket hung up". The server and client works fine with web browsers Chrome and Firefox but not with react native. Can someone help? Thanks in advance.

socketcluster-server@5.14.0 socketcluster-client@5.5.1

import socketCluster from 'socketcluster-client'; const socketOptions = { hostname: 'xxx.xxxx.xxx', secure : true, port: 443 };

this.chatsocket = socketCluster.connect(socketOptions); this.chatsocket.on('connect', this.onSocketConnect.bind(this)); this.chatsocket.on('proxyReply', this.onSocketMessage.bind(this)); this.chatsocket.on('error', this.onSocketError.bind(this));

SocketProtocolError {name: "SocketProtocolError", message: "Socket hung up", code: 1006, stack: "SocketProtocolError: Socket hung up↵ at SCSocke…m=android&dev=true&hot=true&minify=false:8669:42)"}

cogmeta commented 7 years ago

socketerror

jondubois commented 7 years ago

@cogmeta Did you manage to find the solution?

cogmeta commented 7 years ago

@jondubois Yes, Thank you. There were lots of things to fix (protocol option in socketOption, uws engine on server side, nginx settings). I will write a checklist that might benefit others as well while troubleshooting.

Louies89 commented 6 years ago

Hi @cogmeta I am trying to connect to socketcluster server using react native. I am using below scWorker code to connect: class Worker extends SCWorker { run() { var httpServer = this.httpServer; var scServer = this.scServer; scServer.on('connection', function (socket) { console.log('client :'+ socket.id + ' connected.'); }) } }

And from client side var Newsocket = socketCluster.connect({ hostname: 'localhost', port: 80})

But it throws following error image Can you help me out please?

And is it, I have to connect to the server using http first then i have to fire var Newsocket = socketCluster.connect({ hostname: 'localhost', port: 80}) from client side?

sacOO7 commented 6 years ago

Use secure: true during making connection with server.

On Feb 6, 2018 12:56 PM, "Louies89" notifications@github.com wrote:

Hi @cogmeta https://github.com/cogmeta I am trying to connect to socketcluster server using react native. I am using below scWorker code to connect: class Worker extends SCWorker { run() { var httpServer = this.httpServer; var scServer = this.scServer; scServer.on('connection', function (socket) { console.log('client :'+ socket.id + ' connected.'); }) } }

And from client side var Newsocket = socketCluster.connect({ hostname: 'localhost', port: 80})

But it throws following error

Can anyone help me out please? And is it, I have to connect to the server using http first then i have to fire var Newsocket = socketCluster.connect({ hostname: 'localhost', port: 80}) from client side?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SocketCluster/socketcluster-client/issues/82#issuecomment-363334064, or mute the thread https://github.com/notifications/unsubscribe-auth/AP8vSSqPE54XseoDj5eEI09QBws1KFKRks5tR_6kgaJpZM4N9LO6 .