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

JSON-Data? #5

Open
TexxMedia opened this issue Aug 14, 2015 · 10 comments
Open

JSON-Data? #5

TexxMedia opened this issue Aug 14, 2015 · 10 comments

Comments

@TexxMedia
Copy link

Hi,

how i can change this great Class to send json-data?
$data = json_encode ( array ( 'var' => 'content' ) )

fwrite($fd, $this->hybi10Encode('42["' . $action . '", "' . addslashes($data) . '"]'));

Thank you

@TexxMedia TexxMedia changed the title JSON-Data? label:"help wanted" JSON-Data? Aug 14, 2015
@psinetron
Copy link
Owner

you need to remove addslashes and send data as JSON

Четверг, 13 августа 2015, 17:07 -07:00 от TexxMedia notifications@github.com:

Hi,
how i can change this great Class to send json-data?
$data = json_encode ( array ( 'var' => 'content' ) )
fwrite($fd, $this->hybi10Encode('42["' . $action . '", "' . addslashes($data) . '"]'));
Thank you

Reply to this email directly or view it on GitHub .

Фаиль Галиевич Шахмаев
http://slybeaver.ru

@NickyX3
Copy link

NickyX3 commented Mar 15, 2016

Спасибо друг за простой такой клиент
А как послать нормальный js объект так как его родной socket.io клиент посылает? чтоб Json не парсить :-)

@VigibotDev
Copy link

Please give a sample, I always get a string on server side. How to correctly send JSON data ?

@psinetron
Copy link
Owner

You can send the JSON data as String. Just use json-encode/json_decode method.
http://php.net/manual/en/function.json-decode.php
http://php.net/manual/en/function.json-encode.php

@VigibotDev
Copy link

VigibotDev commented Oct 3, 2017

I know this, but I need a JSON on server side because it's a bridge and I don't want to modify the server code.
The php client must be mimic the original socket.io client it's important.

My code :

<?php
 include_once("socket.io.php");

 $socketio = new SocketIO();

 $data = json_encode(array("commande" => "c"));

 if($socketio -> send("127.0.0.1", 83, "robotserveur", $data))
  echo "OK";
 else
  echo "NOK";

?>

My mod inside your class :

            //fwrite($fd, $this->hybi10Encode('42["' . $action . '", "' . addslashes($data) . '"]'));
            fwrite($fd, $this->hybi10Encode('42["' . $action . '", "' . $data . '"]'));

My server don't get the "robotserveur" (but I get a string type with your addslashes!)

@VigibotDev
Copy link

I must wireshark the content:(

@VigibotDev
Copy link

VigibotDev commented Oct 3, 2017

WebSocket content is not clear (gzip) ! I can't fgrep my string value inside a JSON.
I can get some ASCII from the server
Do you have an idea to debug this ?

(root|/var/www/temp/pascal) tcpdump -i lo port 83 -A -vv
tcpdump: listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
21:26:59.726477 IP (tos 0x0, ttl 64, id 25561, offset 0, flags [DF], proto TCP (6), length 60)
    localhost.39382 > localhost.83: Flags [S], cksum 0xfe30 (incorrect -> 0xd43c), seq 2589105809, win 43690, options [mss 65495,sackOK,TS val 10288456 ecr 0,nop,wscale 7], length 0
E..<c.@.@..............S.R...........0.........
...H........
21:26:59.726494 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    localhost.83 > localhost.39382: Flags [S.], cksum 0xfe30 (incorrect -> 0x1dc1), seq 1883916347, ack 2589105810, win 43690, options [mss 65495,sackOK,TS val 10288456 ecr 10288456,nop,wscale 7], length 0
E..<..@.@.<..........S..pJH;.R.......0.........
...H...H....
21:26:59.726507 IP (tos 0x0, ttl 64, id 25562, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.39382 > localhost.83: Flags [.], cksum 0xfe28 (incorrect -> 0xf005), seq 1, ack 1, win 342, options [nop,nop,TS val 10288456 ecr 10288456], length 0
E..4c.@.@..............S.R..pJH<...V.(.....
...H...H
21:26:59.726554 IP (tos 0x0, ttl 64, id 25563, offset 0, flags [DF], proto TCP (6), length 257)
    localhost.39382 > localhost.83: Flags [P.], cksum 0xfef5 (incorrect -> 0xb4e5), seq 1:206, ack 1, win 342, options [nop,nop,TS val 10288456 ecr 10288456], length 205
E...c.@.@..............S.R..pJH<...V.......
...H...HGET /socket.io/?EIO=2&transport=websocket HTTP/1.1
Host: http://127.0.0.1:83
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Key: fqYLB8J7MFpHLG34pDgV2w==
Sec-WebSocket-Version: 13
Origin: *


21:26:59.727196 IP (tos 0x0, ttl 64, id 46453, offset 0, flags [DF], proto TCP (6), length 239)
    localhost.83 > localhost.39382: Flags [P.], cksum 0xfee3 (incorrect -> 0x6fb3), seq 1:188, ack 206, win 350, options [nop,nop,TS val 10288456 ecr 10288456], length 187
E....u@.@............S..pJH<.R._...^.......
...H...HHTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: hZotW5irZCZZpiERYqaOKAOHXh8=
Sec-WebSocket-Version: 13
WebSocket-Server: uWebSockets


21:26:59.727213 IP (tos 0x0, ttl 64, id 25564, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.39382 > localhost.83: Flags [.], cksum 0xfe28 (incorrect -> 0xee75), seq 206, ack 188, win 350, options [nop,nop,TS val 10288456 ecr 10288456], length 0
E..4c.@.@..............S.R._pJH....^.(.....
...H...H
21:26:59.727290 IP (tos 0x0, ttl 64, id 25565, offset 0, flags [DF], proto TCP (6), length 100)
    localhost.39382 > localhost.83: Flags [P.], cksum 0xfe58 (incorrect -> 0xc39c), seq 206:254, ack 188, win 350, options [nop,nop,TS val 10288456 ecr 10288456], length 48
E..dc.@.@..............S.R._pJH....^.X.....
...H...H......'..9a..tg..ie..i1..9h..x|..z}..G1..9p..f1.
21:26:59.727420 IP (tos 0x0, ttl 64, id 46454, offset 0, flags [DF], proto TCP (6), length 140)
    localhost.83 > localhost.39382: Flags [P.], cksum 0xfe80 (incorrect -> 0xfc53), seq 188:276, ack 254, win 350, options [nop,nop,TS val 10288456 ecr 10288456], length 88
E....v@.@............S..pJH..R.....^.......
...H...H.V0{"sid":"-EPjOyjjiiBn4fiWAADv","upgrades":[],"pingInterval":25000,"pingTimeout":60000}
21:26:59.727459 IP (tos 0x0, ttl 64, id 25566, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.39382 > localhost.83: Flags [F.], cksum 0xfe28 (incorrect -> 0xedec), seq 254, ack 276, win 350, options [nop,nop,TS val 10288456 ecr 10288456], length 0
E..4c.@.@..............S.R..pJIO...^.(.....
...H...H
21:26:59.727617 IP (tos 0x0, ttl 64, id 46455, offset 0, flags [DF], proto TCP (6), length 56)
    localhost.83 > localhost.39382: Flags [P.], cksum 0xfe2c (incorrect -> 0x38ae), seq 276:280, ack 255, win 350, options [nop,nop,TS val 10288456 ecr 10288456], length 4
E..8.w@.@..F.........S..pJIO.R.....^.,.....
...H...H..40
21:26:59.727634 IP (tos 0x0, ttl 64, id 34400, offset 0, flags [DF], proto TCP (6), length 40)
    localhost.39382 > localhost.83: Flags [R], cksum 0xddd1 (correct), seq 2589106064, win 0, length 0
E..(.`@.@..m...........S.R......P.......
^C
11 packets captured
24 packets received by filter
2 packets dropped by kernel

@VigibotDev
Copy link

No news to get a server side object and not a string ?

@VigibotDev
Copy link

Socket.io has "automatic JSON encoding/decoding" when I use .emit()
How to spoof the socket.io .emit() behavior ? How to force the server side (nodejs) to parce my JSON and return an object ?

@VigibotDev
Copy link

I found the problem !!! Don't double quote the JSON string ! and I finally get my server side object :)

socket.io sample frame :

42["eventName", {headers map}, data(primitive, array or object)]

42["createUser", {"requestId": "UUID"}, {
    "firstName": "John",
    "lastName": "Dow"
}]

42["deleteUser", {}, 10]

42["getUsers", {}, [1,2,3,4,5]]

Mod inside the class :

            //fwrite($fd, $this->hybi10Encode('42["' . $action . '", "' . addslashes($data) . '"]'));
            //fwrite($fd, $this->hybi10Encode('42["' . $action . '", "' . $data . '"]'));
            fwrite($fd, $this->hybi10Encode('42["' . $action . '", ' . $data . ']'));

My PHP socket.io client :

<?php
 include_once("socket.io.php");
 
 $socketio = new SocketIO();
 
 $data = json_encode(array("commande" => "c"));
 
 if($socketio -> send("127.0.0.1", 83, "robotserveur", $data))
  echo "OK";
 else
  echo "NOK";
?>

issue closed:)

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

4 participants