I'm trying to load a csv file with stock prices into a prices table.
The csv file has 3 lines that I want to ignore, including a blank one.
When I set IGNORE 1 LINES, it runs into an error processing the column headers.
When I set IGNORE 2 LINES, it consistently skips the first line of data.
All other data is loaded just fine, starting from the 2nd data row ("11-03-2020" in this case).
How do I fix this, without changing the data in the csv?
The csv looks like this:
"Some instructions"
"date";"price"
"12-03-2020";133.08
"11-03-2020";143.68
"10-03-2020";149.14
...
The CREATE TABLE code:
CREATE TABLE `prices` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`isin` CHAR(12) NOT NULL,
`price_date` DATE NOT NULL,
`price` DECIMAL(10,2) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `isin_date` (`isin`, `price_date`),
CONSTRAINT `prices_stocks` FOREIGN KEY (`isin`) REFERENCES `stocks` (`isin`) ON UPDATE CASCADE ON DELETE NO ACTION
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
ROW_FORMAT=DYNAMIC
AUTO_INCREMENT=157532
;
The LOAD DATA SQL statement:
LOAD DATA LOCAL INFILE 'price_history_LU0792910050.csv'
REPLACE INTO TABLE stock_db.prices
CHARACTER SET utf8
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 2 LINES
(#vdate, #vprice)
SET
isin = 'LU0792910050',
price_date = STR_TO_DATE(#vdate, '%d-%m-%Y'),
price = #vprice;
hexdump of an example csv:
00000000: EF BB BF 22 44 65 20 69 6E 73 74 65 6C 6C 69 6E ..."De instellin
00000010: 67 65 6E 20 76 61 6E 20 75 77 20 45 78 63 65 6C gen van uw Excel
00000020: 2D 73 6F 66 74 77 61 72 65 20 6B 75 6E 6E 65 6E -software kunnen
00000030: 20 64 65 20 77 65 65 72 67 61 76 65 20 76 61 6E de weergave van
00000040: 20 6F 6E 64 65 72 73 74 61 61 6E 64 65 20 67 65 onderstaande ge
00000050: 67 65 76 65 6E 73 20 62 65 C3 AF 6E 76 6C 6F 65 gevens be..nvloe
00000060: 64 65 6E 20 64 6F 6F 72 20 64 65 20 63 65 6C 6F den door de celo
00000070: 70 6D 61 61 6B 20 76 61 6E 20 64 65 20 67 65 67 pmaak van de geg
00000080: 65 76 65 6E 73 63 61 74 65 67 6F 72 69 65 20 28 evenscategorie (
00000090: 62 69 6A 76 2E 20 61 61 6E 74 61 6C 20 69 6E 20 bijv. aantal in
000000A0: 70 6C 61 61 74 73 20 76 61 6E 20 64 61 74 75 6D plaats van datum
000000B0: 29 2E 22 0D 0A 0D 0A 22 64 61 74 65 22 3B 22 70 )."...."date";"p
000000C0: 72 69 63 65 22 0D 0A 22 31 35 2D 30 37 2D 32 30 rice".."15-07-20
000000D0: 32 30 22 3B 35 31 2E 37 36 0D 0A 22 31 34 2D 30 20";51.76.."14-0
000000E0: 37 2D 32 30 32 30 22 3B 35 31 2E 31 37 0D 0A 22 7-2020";51.17.."
000000F0: 31 33 2D 30 37 2D 32 30 32 30 22 3B 35 31 2E 30 13-07-2020";51.0
00000100: 33 0D 0A 22 31 30 2D 30 37 2D 32 30 32 30 22 3B 3.."10-07-2020";
(Hexdump was not installed on Synology, so used Python hexdump. Hope this works)
"12-03-2020" cannot be put directly be put into a DATE column. Instead, put it into an # variable, then use str_to_date(...). (Let us know if you need help; there are many examples floating around.)
I see C3 AF, which is utf8 for ï, as in ... beïnvloegen ... -- Does that sound "right"? CHARACTER SET utf8 should have read it correctly.
The initial EF BB BF is "BOM". I don't know if LOAD FILE is smart enough to silently skip over it. This may be causing your problem. One approach is to edit the file to remove the first 3 bytes.
Later comes 0D 0A 0D 0A, which matches your description of there being 3 header lines, the second being blank. And LINES TERMINATED BY '\r\n' should be correct for that.
Related
I have captured a packet using libpcap and have the packet data in a char array. When I print it in hex and ascii the output is
47 45 54 20 2f 62 72 6f 77 73 65 2f 64 69 63 74 GET /browse/dict
69 6f 6e 61 72 79 3f 73 3d 74 20 48 54 54 50 2f ionary?s=t HTTP/
31 2e 31 0d 0a 48 6f 73 74 3a 20 77 77 77 2e 64 1.1..Host: www.d
69 63 74 69 6f 6e 61 72 79 2e 63 6f 6d 0d 0a 55 ictionary.com..U
73 65 72 2d 41 67 65 6e 74 3a 20 4d 6f 7a 69 6c ser-Agent: Mozil
.....
......
41 31 25 32 43 31 30 31 25 33 41 31 25 32 43 32 A1%2C101%3A1%2C2
25 33 41 31 25 32 43 31 30 32 25 33 41 31 25 32 %3A1%2C102%3A1%2
43 31 30 33 25 33 41 31 25 32 43 33 25 33 41 31 C103%3A1%2C3%3A1
............
.....
Now I want to convert above http request/response from captured packet to html tags. How can I do that?
I have receive some kind of below regrex message with random set as below pattern. I want to filter this message by insert filter table in SQL developer how to make the pattern to filter out. Query to insert the filter is below.
37 35 32 41 44 44 37 36 32 46 34 34 34 45 45 34 42 31 31 34 31 41 36 43 39
44 37 41 35 45 35 39 20 44 61 74 65 54 69 6D 65 20 3A 20 53 75 6E 20 41 75 67 20 32 30
20 32 30 3A 30 37 3A 33 39 20 41 53 54 20 32 30 31 37 2C 20 65 72 72 6F 72 4D 65 73 73
61 67 65 20 3A 20 45 78 63 65 70 74 69 6F 6E 20 67 65 6E 65 72 61 74 65 64 20 6F 6E 20
D9 A2 D9 A0 D9 A1 D9 A7 2D D9 A0 D9 A8 2D D9 A2 D9 A0 20 D9 A2 D9 A0 3A D9 A0 D9 A7 3A D9
A5 D9 A0 0A 0A 45 78 63 65 70 74 69 6F 6E 3A 20 6A 61 76 61 2E 6C
insert
into FILTER_IGNR (
ID_ALARM_FILTER_IGNR,
FILTER_PATTERN,
CREATED_DATE_TIME,
UPDATED_DATE_TIME,
IS_ACTIVE)
select MAX(ID_ALARM_FILTER_IGNR)+1,
'.*ERROR.*', -- Check and change in this one
sysdate,
sysdate,
1
from FILTER_IGNR
I was working on a project and just when I saved the file, my power cut off. Now my html file is corrupted and I have no backup of it.
I just remembered that I might have a cache of it in Firefox. So, first I tried CacheViewer from Firefox official add-ons store. This add-on would install and then required a restart, after the restart it would disappear.
So instead, I tried the old fashioned way. I went to about:cache > Local Storage and whew, I was lucky enough that it was there and wasn't replaced with the blank corrupted html file.
Now I have some sort (Catch Entry Information) of file. The left side has the binary code, while the right side has the proper html code with some unnecessary . periods in it.
This is what my this file looks like:
00000000: 3c 21 64 6f 63 74 79 70 65 20 68 74 6d 6c 3e 0d <!doctype html>.
00000010: 0a 3c 68 74 6d 6c 3e 0d 0a 3c 68 65 61 64 3e 0d .<html>..<head>.
00000020: 0a 3c 6d 65 74 61 20 63 68 61 72 73 65 74 3d 22 .<meta charset="
00000030: 75 74 66 2d 38 22 3e 0d 0a 3c 74 69 74 6c 65 3e utf-8">..<title>
00000040: 46 69 74 41 70 70 3c 2f 74 69 74 6c 65 3e 0d 0a FitApp</title>..
00000050: 3c 73 74 79 6c 65 3e 40 66 6f 6e 74 2d 66 61 63 <style>#font-fac
00000060: 65 20 7b 0a 20 20 66 6f 6e 74 2d 66 61 6d 69 6c e {. font-famil
00000070: 79 3a 20 22 52 6f 62 6f 74 6f 2d 6c 69 67 68 74 y: "Roboto-light
00000080: 22 3b 0a 20 20 73 72 63 3a 20 75 72 6c 28 22 2e ";. src: url(".
00000090: 2e 2f 66 6f 6e 74 73 2f 52 6f 62 6f 74 6f 2d 4c ./fonts/Roboto-L
000000a0: 69 67 68 74 2e 74 66 66 22 29 20 66 6f 72 6d 61 ight.tff") forma
000000b0: 74 28 22 74 72 75 65 74 79 70 65 22 29 2c 20 6c t("truetype"), l
000000c0: 6f 63 61 6c 28 22 52 6f 62 6f 74 6f 2d 6c 69 67 ocal("Roboto-lig
000000d0: 68 74 22 29 20 66 6f 72 6d 61 74 28 22 74 72 75 ht") format("tru
000000e0: 65 74 79 70 65 22 29 3b 0a 20 20 66 6f 6e 74 2d etype");. font-
000000f0: 77 65 69 67 68 74 3a 20 34 30 30 3b 0a 7d 0a 40 weight: 400;.}.#
How do I go about decoding this?
If there is a better way to download a catch file from Mozilla Firefox, please do mention.
Steps:
Copy all of that text into a text document, and save it.
Edit that text to make it only the column of hexadecimal characters.
Options for how to do this include shell commands, a find-replace using regex, or a column editing mode in your text editor.
Convert those hex encoded bytes into a binary file.
You should be able to paste those characters into any decent hex editor, and save it as a file.
BTW, the .'s in this case are substituted to replace the newline characters.
I'm trying to find a way to enable/disable my router whithout the need for manually using the browser. After a bit of snooping, it seems to me that I have to send a request like that [from WireShark]:
0000 9c 97 26 c9 c2 20 b0 48 7a 80 52 9c 08 00 45 00 ..&.. .Hz.R...E.
0010 02 2e 28 89 40 00 80 06 00 00 c0 a8 00 02 c0 a8 ..(.#...........
0020 00 01 d6 a8 00 50 34 fd c9 8d c9 ef dd 2d 50 18 .....P4......-P.
0030 fe da 83 74 00 00 50 4f 53 54 20 2f 77 61 6e 53 ...t..POST /wanS
0040 74 61 74 75 73 2e 6c 70 20 48 54 54 50 2f 31 2e tatus.lp HTTP/1.
0050 31 0d 0a 48 6f 73 74 3a 20 31 39 32 2e 31 36 38 1..Host: 192.168
0060 2e 30 2e 31 0d 0a 55 73 65 72 2d 41 67 65 6e 74 .0.1..User-Agent
0070 3a 20 4d 6f 7a 69 6c 6c 61 2f 35 2e 30 20 28 57 : Mozilla/5.0 (W
0080 69 6e 64 6f 77 73 20 4e 54 20 36 2e 31 3b 20 57 indows NT 6.1; W
0090 4f 57 36 34 3b 20 72 76 3a 33 36 2e 30 29 20 47 OW64; rv:36.0) G
00a0 65 63 6b 6f 2f 32 30 31 30 30 31 30 31 20 46 69 ecko/20100101 Fi
00b0 72 65 66 6f 78 2f 33 36 2e 30 0d 0a 41 63 63 65 refox/36.0..Acce
00c0 70 74 3a 20 74 65 78 74 2f 68 74 6d 6c 2c 61 70 pt: text/html,ap
00d0 70 6c 69 63 61 74 69 6f 6e 2f 78 68 74 6d 6c 2b plication/xhtml+
00e0 78 6d 6c 2c 61 70 70 6c 69 63 61 74 69 6f 6e 2f xml,application/
00f0 78 6d 6c 3b 71 3d 30 2e 39 2c 2a 2f 2a 3b 71 3d xml;q=0.9,*/*;q=
0100 30 2e 38 0d 0a 41 63 63 65 70 74 2d 4c 61 6e 67 0.8..Accept-Lang
0110 75 61 67 65 3a 20 69 74 2d 49 54 2c 69 74 3b 71 uage: it-IT,it;q
0120 3d 30 2e 38 2c 65 6e 2d 55 53 3b 71 3d 30 2e 35 =0.8,en-US;q=0.5
0130 2c 65 6e 3b 71 3d 30 2e 33 0d 0a 41 63 63 65 70 ,en;q=0.3..Accep
0140 74 2d 45 6e 63 6f 64 69 6e 67 3a 20 67 7a 69 70 t-Encoding: gzip
0150 2c 20 64 65 66 6c 61 74 65 0d 0a 44 4e 54 3a 20 , deflate..DNT:
0160 31 0d 0a 52 65 66 65 72 65 72 3a 20 68 74 74 70 1..Referer: http
0170 3a 2f 2f 31 39 32 2e 31 36 38 2e 30 2e 31 2f 77 ://192.168.0.1/w
0180 61 6e 53 74 61 74 75 73 2e 6c 70 0d 0a 43 6f 6f anStatus.lp..Coo
0190 6b 69 65 3a 20 78 41 75 74 68 5f 53 45 53 53 49 kie: xAuth_SESSI
01a0 4f 4e 5f 49 44 3d 49 4d 45 74 4f 38 44 4c 45 73 ON_ID=IMEtO8DLEs
01b0 51 70 6d 54 77 69 64 67 43 59 6c 51 41 3d 0d 0a QpmTwidgCYlQA=..
01c0 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 Connection: keep
01d0 2d 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d -alive..Content-
01e0 54 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f Type: applicatio
01f0 6e 2f 78 2d 77 77 77 2d 66 6f 72 6d 2d 75 72 6c n/x-www-form-url
0200 65 6e 63 6f 64 65 64 0d 0a 43 6f 6e 74 65 6e 74 encoded..Content
0210 2d 4c 65 6e 67 74 68 3a 20 32 39 0d 0a 0d 0a 72 -Length: 29....r
0220 6e 3d 49 4d 45 74 4f 38 44 4c 45 73 51 70 6d 54 n=IMEtO8DLEsQpmT
0230 77 69 64 67 43 59 6c 51 41 25 33 44 widgCYlQA%3D
As you can see, it ends with 'rn=IMEtO8DLEsQpmTwidgCYlQA%3D', that is the session cookie.
Putting a 'normal' request the router goes back to index instead of performing the action, probably for the lack of 'rn=IMEtO8DLEsQpmTwidgCYlQA%3D'.
Until now, I tried using Wget (under windows...) but I can't find a way to add the last info.
So I would know if
there is a way to add an header that is not header-compliant (use of = instead of : ) using wGet or if
there is a tool more suited for that task (I'm looking for cUrl but I don't think it acts different from wGet).
The batch file (plain ol' DOS) I wrote for testing wGet is:
#title %~n0
#cls
#set _wget="C:\Program Files (x86)\GnuWin32\bin\wget"
#set _url=http://192.168.0.1/
#set _urls=http://192.168.0.1/standard.lp
#set _urlw=http://192.168.0.1/wanStatus.lp
#set _post=--post-data="/wanStatus.lp HTTP/1.1"
#set _cook=./cookies.txt
#set _hdr1="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
#set _hdr2="Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3"
#set _hdr3="Accept-Encoding: gzip, deflate"
#set _hdr4="DNT: 1"
#set _agnt="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0"
#set _rfr="Referer: http://192.168.0.1/wanStatus.lp"
#set _opt=--server-response --timestamping --user-agent=%_agnt% --keep-session-cookies --referer=%_rfr% --save-headers --header=%_hdr1% --header=%_hdr2% --header=%_hdr3% --header=%_hdr4% --debug
%_wget% %_opt% --save-cookies %_cook% %_url%
%_wget% %_opt% --load-cookies %_cook% %_urlw%
#FOR /F "eol=# tokens=1,6,7* delims= " %%i in (F:\wget\cookies.txt) do #(
#echo i=%%i j=%%j k=%%k l=%%l
#set _ckhost=%%i
#set _ckname=%%j
#set _ckval=%%k
)
#echo host=%_ckhost% cookie name=%_ckname% value=%_ckval%
#if "%_ckname%"=="xAuth_SESSION_ID" set _rn=rn=%_ckval%
#if "%_rn:~-1%"=="=" set _rn=%_rn:~0,-1%%%3D
#echo _rn='%_rn%'
%_wget% %_opt% --load-cookies %_cook% %_post% --header="%_rn%" %_url%
but it ends up this way:
F:\wget>"C:\Program Files (x86)\GnuWin32\bin\wget" --server-response --timestamping --user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0" --keep-session-cookies --referer="Referer: http://192.168.0.1/wanStatus.lp" --save-headers --header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" --header="Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3" --header="Accept-Encoding: gzip, deflate" --header="DNT: 1" --debug --load-cookies ./cookies.txt --post-data="/wanStatus.lp HTTP/1.1" --header="rn=MGyN4YpepJoE6kSXPVT9lgA%3D" http://192.168.0.1/
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files (x86)\GnuWin32/etc/wgetrc
Setting --load-cookies (loadcookies) to ./cookies.txt
Setting --post-data (postdata) to /wanStatus.lp HTTP/1.1
Setting --header (header) to rn=MGyN4YpepJoE6kSXPVT9lgA%3D
C:\Program Files (x86)\GnuWin32\bin\wget: --header: intestazione "rn=MGyN4YpepJoE6kSXPVT9lgA%3D" non valida.
Thank you very much for any suggestion! Or for links pointing to pages where I can find a solution (I spent a looot of time googling around...).
Luca
Note: I think it's useless to add here the HTML and JS code of the page in the router that generate the line rn=MGyN4YpepJoE6kSXPVT9lgA%3D, but if you need it, I can report it.
Look careful at the captured data and you might notice that these data are not part of the header. The header ends with \r\n\r\n (Bytes 021b..021e) and your "session cookie" is not a cookie (which would be part of the header) but the body of the POST request. Thus you need to use --post-data 'rn=MGyN...'
With a websocket server(C program) running in Cygwin, which does the handshaking&echoing back the messages from client.
With Firefox(Version 13.0.1), the two parties work together very well - handshaking , receiving and echoing back.
But with Chrome(Version 23.0.1271.97 m), after the handshaking step, the client always triggers onerror - "undefined", then onclose.
I was wondering:
Are there any differences between Firefox and Chrome how they handle websocket?
Here is the HTML code(Thanks to stackoverflow guys contribution):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function connect() {
var ws = new WebSocket("ws://localhost:8080/service");
ws.onopen = function () {
alert("About to send data");
ws.send("Hello World"); // I WANT TO SEND THIS MESSAGE TO THE SERVER!!!!!!!!
alert("Message sent!");
};
ws.onmessage = function (evt) {
alert("About to receive data");
var received_msg = evt.data;
alert("Message received = "+received_msg);
};
ws.onclose = function () {
// websocket is closed.
alert("Connection is closed...");
};
ws.onerror = function (evt) {
alert("ERROR: "+evt.data);
};
};
</script>
</head>
<body style="font-size:xx-large" >
<div>
Click here to start</div>
</body>
</html>
Here is data log captured on server side with Firefox:
websocket server received:
0001 47 45 54 20 2f 73 65 72 76 69 63 65 20 48 54 54 GET /service HTT
0002 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a 20 6c 6f 63 P/1.1..Host: loc
0003 61 6c 68 6f 73 74 3a 38 30 38 30 0d 0a 55 73 65 alhost:8080..Use
0004 72 2d 41 67 65 6e 74 3a 20 4d 6f 7a 69 6c 6c 61 r-Agent: Mozilla
0005 2f 35 2e 30 20 28 57 69 6e 64 6f 77 73 20 4e 54 /5.0 (Windows NT
0006 20 36 2e 31 3b 20 57 4f 57 36 34 3b 20 72 76 3a 6.1; WOW64; rv:
0007 31 33 2e 30 29 20 47 65 63 6b 6f 2f 32 30 31 30 13.0) Gecko/2010
0008 30 31 30 31 20 46 69 72 65 66 6f 78 2f 31 33 2e 0101 Firefox/13.
0009 30 2e 31 0d 0a 41 63 63 65 70 74 3a 20 74 65 78 0.1..Accept: tex
0010 74 2f 68 74 6d 6c 2c 61 70 70 6c 69 63 61 74 69 t/html,applicati
0011 6f 6e 2f 78 68 74 6d 6c 2b 78 6d 6c 2c 61 70 70 on/xhtml+xml,app
0012 6c 69 63 61 74 69 6f 6e 2f 78 6d 6c 3b 71 3d 30 lication/xml;q=0
0013 2e 39 2c 2a 2f 2a 3b 71 3d 30 2e 38 0d 0a 41 63 .9,*/*;q=0.8..Ac
0014 63 65 70 74 2d 4c 61 6e 67 75 61 67 65 3a 20 65 cept-Language: e
0015 6e 2d 75 73 2c 65 6e 3b 71 3d 30 2e 35 0d 0a 41 n-us,en;q=0.5..A
0016 63 63 65 70 74 2d 45 6e 63 6f 64 69 6e 67 3a 20 ccept-Encoding:
0017 67 7a 69 70 2c 20 64 65 66 6c 61 74 65 0d 0a 43 gzip, deflate..C
0018 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 2d onnection: keep-
0019 61 6c 69 76 65 2c 20 55 70 67 72 61 64 65 0d 0a alive, Upgrade..
0020 53 65 63 2d 57 65 62 53 6f 63 6b 65 74 2d 56 65 Sec-WebSocket-Ve
0021 72 73 69 6f 6e 3a 20 31 33 0d 0a 4f 72 69 67 69 rsion: 13..Origi
0022 6e 3a 20 6e 75 6c 6c 0d 0a 53 65 63 2d 57 65 62 n: null..Sec-Web
0023 53 6f 63 6b 65 74 2d 4b 65 79 3a 20 61 41 48 6e Socket-Key: aAHn
0024 63 31 77 66 6e 68 39 39 53 6d 59 67 4d 50 6b 4d c1wfnh99SmYgMPkM
0025 57 77 3d 3d 0d 0a 50 72 61 67 6d 61 3a 20 6e 6f Ww==..Pragma: no
0026 2d 63 61 63 68 65 0d 0a 43 61 63 68 65 2d 43 6f -cache..Cache-Co
0027 6e 74 72 6f 6c 3a 20 6e 6f 2d 63 61 63 68 65 0d ntrol: no-cache.
0028 0a 55 70 67 72 61 64 65 3a 20 77 65 62 73 6f 63 .Upgrade: websoc
0029 6b 65 74 0d 0a 0d 0a ket....
websocket server sent:
0001 48 54 54 50 2f 31 2e 31 20 31 30 31 20 53 77 69 HTTP/1.1 101 Swi
0002 74 63 68 69 6e 67 20 50 72 6f 74 6f 63 6f 6c 73 tching Protocols
0003 0d 0a 55 70 67 72 61 64 65 3a 20 77 65 62 73 6f ..Upgrade: webso
0004 63 6b 65 74 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e cket..Connection
0005 3a 20 55 70 67 72 61 64 65 0d 0a 53 65 63 2d 57 : Upgrade..Sec-W
0006 65 62 53 6f 63 6b 65 74 2d 41 63 63 65 70 74 3a ebSocket-Accept:
0007 20 74 66 48 33 51 6f 70 47 2f 61 50 78 49 4c 65 tfH3QopG/aPxILe
0008 55 75 49 39 48 38 34 46 49 35 63 77 3d 0d 0a 53 UuI9H84FI5cw=..S
0009 65 63 2d 57 65 62 53 6f 63 6b 65 74 2d 50 72 6f ec-WebSocket-Pro
0010 74 6f 63 6f 6c 3a 20 63 68 61 74 0d 0a 0d 0a tocol: chat....
Sent OKAY.
websocket server received:
0001 81 8b 75 cb 87 1a 3d ae eb 76 1a eb d0 75 07 a7 ..u...=..v...u..
0002 e3 .
websocket server sent:
...
Data log with Chrome:
websocket server received:
0001 47 45 54 20 2f 73 65 72 76 69 63 65 20 48 54 54 GET /service HTT
0002 50 2f 31 2e 31 0d 0a 55 70 67 72 61 64 65 3a 20 P/1.1..Upgrade:
0003 77 65 62 73 6f 63 6b 65 74 0d 0a 43 6f 6e 6e 65 websocket..Conne
0004 63 74 69 6f 6e 3a 20 55 70 67 72 61 64 65 0d 0a ction: Upgrade..
0005 48 6f 73 74 3a 20 6c 6f 63 61 6c 68 6f 73 74 3a Host: localhost:
0006 38 30 38 30 0d 0a 4f 72 69 67 69 6e 3a 20 6e 75 8080..Origin: nu
0007 6c 6c 0d 0a 53 65 63 2d 57 65 62 53 6f 63 6b 65 ll..Sec-WebSocke
0008 74 2d 4b 65 79 3a 20 6a 79 38 30 61 2b 50 72 73 t-Key: jy80a+Prs
0009 35 48 71 62 36 62 58 50 2f 43 58 51 51 3d 3d 0d 5Hqb6bXP/CXQQ==.
0010 0a 53 65 63 2d 57 65 62 53 6f 63 6b 65 74 2d 56 .Sec-WebSocket-V
0011 65 72 73 69 6f 6e 3a 20 31 33 0d 0a 53 65 63 2d ersion: 13..Sec-
0012 57 65 62 53 6f 63 6b 65 74 2d 45 78 74 65 6e 73 WebSocket-Extens
0013 69 6f 6e 73 3a 20 78 2d 77 65 62 6b 69 74 2d 64 ions: x-webkit-d
0014 65 66 6c 61 74 65 2d 66 72 61 6d 65 0d 0a 0d 0a eflate-frame....
websocket server sent:
0001 48 54 54 50 2f 31 2e 31 20 31 30 31 20 53 77 69 HTTP/1.1 101 Swi
0002 74 63 68 69 6e 67 20 50 72 6f 74 6f 63 6f 6c 73 tching Protocols
0003 0d 0a 55 70 67 72 61 64 65 3a 20 77 65 62 73 6f ..Upgrade: webso
0004 63 6b 65 74 0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e cket..Connection
0005 3a 20 55 70 67 72 61 64 65 0d 0a 53 65 63 2d 57 : Upgrade..Sec-W
0006 65 62 53 6f 63 6b 65 74 2d 41 63 63 65 70 74 3a ebSocket-Accept:
0007 20 4d 39 2f 58 41 4e 67 35 52 32 58 4f 4d 50 49 M9/XANg5R2XOMPI
0008 4d 67 2f 54 6b 50 38 6e 5a 38 67 6f 3d 0d 0a 53 Mg/TkP8nZ8go=..S
0009 65 63 2d 57 65 62 53 6f 63 6b 65 74 2d 50 72 6f ec-WebSocket-Pro
0010 74 6f 63 6f 6c 3a 20 63 68 61 74 0d 0a 0d 0a tocol: chat....
Sent OKAY.
Guys.
Here is my experience about the issue.
Yesterday, my php simple chatting socket script worked well in both of firefox and chrome. Suddenly it did not work in chrome today. Not sure why? But after the request header value was printed, I found that the header length was longer than 1024 byte.
(I tested by getting 1024 byte in server.php under a domain without login).
Maybe after I logged into the domain, cache length was added into the http request header.
I increased the length value for socket_read function to 5120 byte before performed handshaking. It was enough value to get full request header.
My problem was solved since server.php handshaking function could validate sec-websocket-key from request header.
Hope other guys to take care of websocket request header length.
Regards,
Yin