Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting 404 error on server and client side says 'Disconnected' #124

Closed
fawad-khalil opened this issue Sep 24, 2016 · 19 comments
Closed

Getting 404 error on server and client side says 'Disconnected' #124

fawad-khalil opened this issue Sep 24, 2016 · 19 comments

Comments

@fawad-khalil
Copy link

When I try to connect to server the response is "GET / HTTP/1.1" 404 342 0.002334
I can connect to the server with another client code written in javascript using socketio but can't connect using Arduino. Please help me it's urgent.
I tested it with javascript sever code and python server code and same results.

@fawad-khalil
Copy link
Author

GET /socket.io/?EIO=3&transport=polling&t=1474750479445-0 HTTP/1.1
Host: 192.168.8.102:5000
Accept: /
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: io=f1de310bb9bf48e2a3bb543b2435a653
DNT: 1
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: null
Connection: keep-alive
Content-Length: 119
Content-Type: application/octet-stream
Date: Sat, 24 Sep 2016 20:42:50 GMT
Set-Cookie: io=980653b7146d4c8595ca7f88369881f4

@fawad-khalil
Copy link
Author

GET /socket.io/?EIO=3&transport=polling&t=1474750479505-1&sid=980653b7146d4c8595ca7f88369881f4 HTTP/1.1
Host: 192.168.8.102:5000
Accept: /
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: io=980653b7146d4c8595ca7f88369881f4
DNT: 1
Origin: null
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: null
Connection: keep-alive
Content-Length: 4
Content-Type: application/octet-stream
Date: Sat, 24 Sep 2016 20:42:50 GMT

@fawad-khalil
Copy link
Author

These are the HTTP transfer when I traced them in my browser plugin when tried to connect to the same server using javascript client code and socketio

@fawad-khalil
Copy link
Author

It seems that this:
"GET/socket.io/EIO=3&transport=polling&t=14747504795051&sid=980653b7146d4c8595ca7f88369881f4 HTTP/1.1"
is not in case of Arduino C code.
It's always: "GET / HTTP/1.1". And hence the 404 response from the server.

@Links2004
Copy link
Owner

socket.io is based on WebSockets, you need additional session handling.
may this helps:
https://github.com/Links2004/arduinoWebSockets/blob/master/examples/WebSocketClientSocketIO/WebSocketClientSocketIO.ino

how do your code looks like?

@fawad-khalil
Copy link
Author

OK I solved it by modifying the url parameter in begin() function. The URL parameter in beginSocketIO() does not do the right thing.

@fawad-khalil
Copy link
Author

Now I ran into another issue, not issue actually. how would I parse the payload from the server if Arduino is acting as a client. I need to know event type and the JSON string from the received payload.

@Links2004
Copy link
Owner

Links2004 commented Sep 26, 2016

may https://gist.github.com/Links2004/25966845ed38278bb4a2f4a44b5a30fb
helps you its my socket.io client (for socket.io 0.9, with 1.0 they changed the protocol but I never update my projects since I not need any of changes they have done)

the message handling is stating here:
https://gist.github.com/Links2004/25966845ed38278bb4a2f4a44b5a30fb#file-socketioclient-cpp-L59
buffer to JSON:
https://gist.github.com/Links2004/25966845ed38278bb4a2f4a44b5a30fb#file-socketioclient-cpp-L140-L141

@fawad-khalil
Copy link
Author

In your socket.io client there is a type SocketIO_msg_t can you please give me that class, also what does that means: [message id ('+')] ':' [message endpoint] ':' [json].

@Links2004
Copy link
Owner

SocketIO_msg_t:
https://gist.github.com/Links2004/25966845ed38278bb4a2f4a44b5a30fb#file-socketioclient-h-L61

 [message id ('+')] ':' [message endpoint] ':' [json]

is the protocol description of the socket.io version 0.9

@fawad-khalil
Copy link
Author

How to retrieve this [json] from this protocol? I guess I would need this [json] part. Can't I do this using your public library WebsocketsClient. Your secret library SocketIO is giving me hard time to get understood and the time is running out.

@fawad-khalil
Copy link
Author

When I use payload with index notation like payload[0] as you performed message type checking in your Socketio client library, my WiFi starts restarting after every connection.

@Links2004
Copy link
Owner

may this helps you:
https://github.com/bblanchon/ArduinoJson/blob/master/examples/JsonParserExample/JsonParserExample.ino
https://github.com/bblanchon/ArduinoJson

I use the same lib to decode json.
the basics are:

    DynamicJsonBuffer jsonBuffer;
    JsonObject& root = jsonBuffer.parseObject((char *) data);

where data points to the json string in the message (payload in the Websocket callback)

@Project-MAR
Copy link

@Fawadkhalil
I face this 404 error too. How you modifying the url parameter in begin() function.

@fawad-khalil
Copy link
Author

fawad-khalil commented Oct 20, 2016

Can you show me the debug trace from serial monitor? Are you trying to connect to socketio server?

@fawad-khalil
Copy link
Author

by the way, just change the default parameter value of url as "/socket.io/?EIO=3" from "/" at
https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSocketsClient.h#L43

@Project-MAR
Copy link

I can fix the problem now. I want to use your code (web socket client side)
to connect with Tornado Web Server on RPi. The Problem is the url path is
not include in your code. So server/client will can not connect together.

I use your code with a little change "webSocket.begin("158.108.166.160",
8880, "/ws");" and then, problem solve

Thx, Ram

On Thu, Oct 20, 2016 at 3:44 PM, FawadKhalil notifications@github.com
wrote:

by the way, just change the default parameter value of url as "/
socket.io/?EIO=3" from "/" at
https://github.com/Links2004/arduinoWebSockets/blob/master/
src/WebSocketsClient.h#L43


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#124 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUWLI1molkK85QFB6iQmLV2HYOV0yVRcks5q1yn9gaJpZM4KFvV_
.

@Project-MAR
Copy link

You can visit my git here:
https://github.com/Project-MAR/RPI-ESP8266-TORNADO-SERVER

On Thu, Oct 20, 2016 at 3:53 PM, Atitep.Ram atitep.ram@gmail.com wrote:

I can fix the problem now. I want to use your code (web socket client
side) to connect with Tornado Web Server on RPi. The Problem is the url
path is not include in your code. So server/client will can not connect
together.

I use your code with a little change "webSocket.begin("158.108.166.160",
8880, "/ws");" and then, problem solve

Thx, Ram

On Thu, Oct 20, 2016 at 3:44 PM, FawadKhalil notifications@github.com
wrote:

by the way, just change the default parameter value of url as "/
socket.io/?EIO=3" from "/" at
https://github.com/Links2004/arduinoWebSockets/blob/master/s
rc/WebSocketsClient.h#L43


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#124 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUWLI1molkK85QFB6iQmLV2HYOV0yVRcks5q1yn9gaJpZM4KFvV_
.

@Links2004
Copy link
Owner

#142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants