WebSocket client library
Diff: Websocket.cpp
- Revision:
- 7:b15978708360
- Parent:
- 6:01a1eb7c0145
- Child:
- 8:ecd914cffdf6
--- a/Websocket.cpp Wed Aug 24 10:49:36 2011 +0000 +++ b/Websocket.cpp Wed Aug 24 11:35:49 2011 +0000 @@ -36,12 +36,23 @@ //ip_domain res = strtok(res, ":"); + + //port + res1 = strtok(NULL, " "); + //port + if (res1 != NULL) { + port = (char *) malloc (sizeof(char) * strlen(res1)); + strcpy(this->port, res1); + } else { + port = (char *) malloc (sizeof(char) * 3); + strcpy(this->port, "80"); + } + if (res != NULL) { ip_domain = (char *) malloc (sizeof(char) * strlen(res)); strcpy(this->ip_domain, res); //if we use ethernet, we must decode ip address or use dnsresolver if (!wifi) { - printf("ethernet use\r\n"); strcpy(buf, res); //we try to decode the ip address if (buf[0] >= '0' && buf[0] <= '9') { @@ -64,16 +75,6 @@ } } } - - //port - res = strtok(NULL, ":"); - if (res != NULL) { - port = (char *) malloc (sizeof(char) * strlen(res)); - strcpy(this->port, res); - } else { - port = (char *) malloc (sizeof(char) * 3); - strcpy(this->port, "80"); - } } } @@ -151,6 +152,7 @@ printf("binderr: %d", bindErr); return false; } + printf("port: %d\r\n", atoi(port)); Timer tmr; @@ -166,36 +168,43 @@ case 0: sprintf(cmd, "GET /%s HTTP/1.1\r\n", path); sock.send(cmd, strlen(cmd)); + printf("cmd: %s\r\n", cmd); i++; break; case 1: sprintf(cmd, "Host: %s:%s\r\n", ip_domain, port); sock.send(cmd, strlen(cmd)); + printf("cmd: %s\r\n", cmd); i++; break; case 2: sprintf(cmd, "Upgrade: WebSocket\r\n"); sock.send(cmd, strlen(cmd)); + printf("cmd: %s\r\n", cmd); i++; break; case 3: sprintf(cmd, "Origin: http:%s:%s\r\n", ip_domain, port); sock.send(cmd, strlen(cmd)); + printf("cmd: %s\r\n", cmd); i++; break; case 4: sprintf(cmd, "Connection: Upgrade\r\n"); sock.send(cmd, strlen(cmd)); + printf("cmd: %s\r\n", cmd); i++; break; case 5: sprintf(cmd, "Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\n"); sock.send(cmd, strlen(cmd)); + printf("cmd: %s\r\n", cmd); i++; break; case 6: sprintf(cmd, "Sec-WebSocket-key2: 12998 5 Y3 1 .P00\r\n\r\n"); sock.send(cmd, strlen(cmd)); + printf("cmd: %s\r\n", cmd); i++; break; case 7: @@ -213,7 +222,7 @@ found = checking.find("HTTP"); if(found != string::npos) { - //printf("checking: %s\r\n", checking); + printf("checking: %s\r\n", checking); i++; break; }