I am attempting to send an HTML page over a WebSocket using C++

EDIT: I've updated the response header to **not** specify 
how many characters are being sent via char response[] = "..."; 
I've added to the header the Content-Type and Content-Length headers
with length value being 1024. The result is still the same. 
The server sends the response to the web page client and the 
web page prints the header information instead of using the HTML tags.

我知道C并不是这种语言的首选语言,但它是我必须使用的语言 .

I have already managed to "establish?" a connection with a client webpage in google chrome. 服务器从客户端获取初始请求,并能够发回客户端正在接受的响应 . 它只是显示错误的部分 .

Request Header:

  • 主持人:hostinfo.com:8xxx

  • 连接:保持活着

  • 升级 - 不安全 - 请求:1

  • DNT:1

  • User-Agent:Mozilla / 5.0(chrome等...)

  • 接受:(加密消息)

Server Response:

  • HTTP / 1.1 200好的

  • 升级 - 不安全 - 请求:1

  • 连接:保持活着

  • 内容长度:1024

  • Content-Type:text / html

  • (使用\ r \ n \ r \ n分隔 Headers 和HTML信息的空间(n后的空格))

  • 测试

  • (和结束页面响应\ r \ n \ r \ n(n后的空格)

但是,当网页连接时, instead of displaying "test" it's displaying the entire set of characters in the header including "HTTP/1.1 200 OK... etc"

我已经在几天内使用thisthis这样的文章,并阅读RFC indexes来达到这一点,但似乎没有针对这个特定问题的任何答案 . 我可以理解导致无法在服务器和客户端之间发送数据的握手错误,但发送标头而不是HTML代码超出了我 . 感谢您的帮助/见解 .

TLDR: Why would the client be displaying the header information rather than using the HTML code to display an HTML page?

Client-Side HTML:

<form action="http://xxxxxxx.com:8xxx" method="POST">
<div>
 <input>
</div>
<div>
 <button>Test Connection</button>
</div>
</form>

Server-Side C++ Code: Header File

#pragma once
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
// Need to link with Ws2_32.lib
#pragma comment (lib, "Ws2_32.lib")
// #pragma comment (lib, "Mswsock.lib")

class html_connection
{
public:
    static int client_handler_thread(int index);
    static int server();
};

Server-Side C++ Code: Class File

#include "pch.h"
#include "html_connection.h"
#pragma warning(disable : 4996)

SOCKET Connections[100]; // client threads (up to 100)
int ConnectionCounter = 0;

int html_connection::server()
{
    WSADATA ws;
    WORD dllV = MAKEWORD(2, 1);
    if (WSAStartup(dllV, &ws) != 0)
    {
        MessageBoxA(NULL, "Winsock startup failed", "Error", MB_OK | MB_ICONERROR);
    }

    SOCKADDR_IN addr; // create an address
    int addrSize = sizeof(addr); //length of address
    addr.sin_addr.s_addr = inet_addr("xxx.x.x.xx"); //Broadcast IP
    addr.sin_port = htons(8000); //Port
    addr.sin_family = AF_INET; // IPv4 socket

    SOCKET s = socket(AF_INET, SOCK_STREAM, NULL); // listener socket
    bind(s, (SOCKADDR*)&addr, sizeof(addr)); // binds address to socket
    listen(s, SOMAXCONN); // max possible listeners

    SOCKET newC; // client socket
    for (int i = 0; i < 100; i++) // ensures limited number of clients can connect
    {
        newC = accept(s, (SOCKADDR*)&addr, &addrSize); // connect

        if (newC == 0) // if client con failed
        {
            std::cout << "connect failed" << std::endl;
        }
        else // connected
        {

            Connections[i] = newC; // store new connection in array of connections
            ConnectionCounter += 1;
            CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)client_handler_thread, (LPVOID)(i), NULL, NULL);
        }
    }
    return 0;
}

int  html_connection::client_handler_thread(int index)
{
    // buffer for the client request
    char clientInput[256];

    // Response to the client
    char response[] = "HTTP/1.1 200 OK \r\n Connection: keep-alive \r\n Content-Length:1024 \r\n Upgrade-Insecure-Requests: 1 \r\n Content-Type: text/html \r\n \r\n\r\n <html> </html> \r\n\r\n ";

    while (true)
    {
        // gets the request from the client and prints it to the console
        recv(Connections[index], clientInput, sizeof(clientInput), 0);
        std::cout << clientInput << std::endl;
        // send server response
        send(Connections[index], response, sizeof(response), 0);
    }

    closesocket(Connections[index]);
}

Output: Client - Webpage (initial page - pre-request)

Output: Client - Webpage (post-request)

Output: Server - Console output (single client connection)