Home > Net >  The problem of websocket, please come in, main is to shake hands
The problem of websocket, please come in, main is to shake hands

Time:09-25

If (strnicmp (C - & gt; R_buffer buf, GET/HTTP, strlen (" GET/HTTP "))==0)
{
Char key [100]={0};
Char sha [100]={0};
Char base64 [100]={0};
Char * p=STRSTR (C - & gt; R_buffer buf, WebSocket - Key: "");
P=& amp; P [strlen (" WebSocket - Key: ")];
Int pos=0;
For (int I=0; i <50; I++)
{
If (* p==' ')
{
* p=* p++;
continue;
}
If ((* p=='\ r') | | (* p=='\ n') | | (* p=='\ r \ n') | | (* p==10) | | (* p==13))
break;
The key [pos++]=* p;
* p=* p++;
}
Strcat (key, "eafa5 E914-47-258 da - 95 ca - C5AB0DC85B11");
//memset (key, 0, sizeof (key));
//strcat (key, "dGhlIHNhbXBsZSBub25jZQ==258 eafa5 E914-47 - da - 95 ca - C5AB0DC85B11");
Strcat (sha, StrSHA1 (key, strlen (key), base64));
ToBase64 (sha, strlen (sha), base64);
Sprintf (C - & gt; W_buffer buf, "HTTP/1.1 101 Switching separate Protocols \ r \ n" \
"The Content - Length: 0 \ r \ n" \
"Upgrade: websocket \ r \ n "
"The Sec - Websocket - Accept: % s \ r \ n" \
"Server: TornadoServer/4.5.1 \ r \ n" \
"Connection: Upgrade", base64);
C - & gt; W_buffer. Len=strlen (C - & gt; W_buffer. Buf);
Len: printf (" % d \ n % s ", C - & gt; W_buffer. Len, C - & gt; W_buffer. Buf);
C - & gt; W_count=strlen (C - & gt; W_buffer. Buf);
Send_Data (C);
}

The above code is in the connection, the handshake messages, but always unsuccessful don't know is what reason, temporarily suspended, please leave QQ is best,

CodePudding user response:

Well your reply, have been solved

CodePudding user response:

VC.NET is what I had never heard of...

CodePudding user response:

You here * p==\ r \ n where there is a bug, \ r \ n is not a string, more problematic, single character comparison ignores \ n

CodePudding user response:

Excuse me the original poster is how to solve? I also encountered the same problem
  • Related