I have developed the following C code to mask data before sending back to web server client which is java script running on Firefox browser using RFC 6455 Protocol.
However I am facing problem as I am not able to see anything on client side.
Some say that its not necessary to mask data when sending from server to client. Is that true ? I can’t see that working in my case.
Let me know if my question is ambiguous somewhere.
Thanks for your kind help.
char frame[131],message[360];
strcpy(message,"Server here !");
frame[0] = '\x81';
frame[1] = 128 + strlen(message);
frame[2] = '\x00';
frame[3] = '\x00';
frame[4] = '\x00';
frame[5] = '\x00';
snprintf(frame+6, 124, "%s", message);
printf("%s", frame);
n = write(newsockfd, frame, strlen(frame));
Do not use the
strlenfunction to get the length of anything but a C-style string. Your frame is not a C-style string. The length of the frame is6 + strlen(message), notstrlen(frame).This is also why
printf("%s", frame);didn’t work. The%sformat specifier is for C-style strings, which your frame isn’t.This assumes your message is a C-style string. If not, you have other bugs since you use
strlento compute its length in the initializer forframe[1].