Home > other >  C implementation of server and WebSocket handshake failure problem
C implementation of server and WebSocket handshake failure problem

Time:10-20

 for (;; ) {
Clientfd=accept (sockfd, (struct sockaddr *) & amp; Client_addr,
& Cliaddr_len);
Printf (" server get connection from % s \ n ", inet_ntoa (
Client_addr. Sin_addr));
Int readize=0;
While ((readize=read (clientfd, buf, MAXLINE)) & gt; 0 {
Printf (" %. * s ", readize, buf);
Length: printf (" % d... \ n ", readize);
}
Write (clientfd, buf, readize);
Close (clientfd);
}

Above is a simple demo server, when I was in shake hands with the WebSocket client also in such a process, to handle the request, if the inclusion
 GET/HTTP/1.1 
Connection: Upgrade
Host: 127.0.0.1:8088
Origin: null
The Sec - WebSocket - Extensions: x - its deflate - frame
The Sec - WebSocket - Key: puVOuWb7rel6z2AVZBKnfw==
The Sec - WebSocket - Version: 13
Upgrade: websocket

Go to parse and then send the head and then return to
 HTTP/1.1 101 Switching separate Protocols 
Connection: Upgrade
Server: beetle websocket Server
Upgrade: WebSocket
Date: Mon, 26 Nov 2012 23:42:44 GMT
Access - Control - Allow - Credentials: true
Access - Control - Allow - Headers: the content-type
The Sec - WebSocket - Accept: FCKgUr8c7OsDsLFeJTWrJw6WO8Q=

Because just learning, now the problem is, I don't understand why every time we do have a close loop, if close the client can get the head, but an error real server has been closed, if not close, the client has been didn't get the data, the problem bothering me for a long time, a great god, please help me to look at, very grateful!
  • Related