-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebsocket.h
More file actions
70 lines (61 loc) · 2.25 KB
/
Copy pathwebsocket.h
File metadata and controls
70 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// websocket.h
//
// Author:
// Brian Sullender
// SULLE WAREHOUSE LLC
//
// Description:
// The header file for the WinHttpWebSocketClient namespace.
//
#ifndef WINHTTP_WEB_SOCKET_CLIENT_H
#define WINHTTP_WEB_SOCKET_CLIENT_H
#include <Windows.h>
#include <winhttp.h>
// Connect flags
#define WEBSOCKET_SECURE_CONNECTION 0x0001
// WinHTTP WebSocket client namespace
namespace WinHttpWebSocketClient
{
// Print a Windows Error Code
void PrintLastError(DWORD errorCode, WCHAR* des, size_t desLen, WCHAR* action, bool append = false);
// Open a certificate from a Windows certificate store
// - If store is NULL then the function searches "My" and "WebHosting" stores
PCCERT_CONTEXT OpenCertificateByName(WCHAR* subjectName, WCHAR* store, bool userStores);
// WebSocket client class
class WebSocketClient {
private:
// Application session handle to use with this connection
HINTERNET hSession;
// Windows connect handle
HINTERNET hConnect;
// The initial HTTP request handle to start the WebSocket handshake
HINTERNET hRequest;
// Windows WebSocket handle
HINTERNET hWebSocket;
// The client certificate used for the connection
PCCERT_CONTEXT pCertContext;
public:
// Error of the called function
DWORD ErrorCode;
// The description of the error code
WCHAR* ErrorDescription;
// The number of characters the ErrorDescription buffer can hold
size_t ErrorBufferLength;
// Initialize the WebSocket client class
DWORD Initialize(HINTERNET hSession, PCCERT_CONTEXT pCertContext);
// Connect to a WebSocket server
DWORD Connect(WCHAR* host, DWORD flags, WCHAR* protocol = NULL);
// Receive data from the WebSocket server
DWORD Receive(void* pBuffer, DWORD dwBufferLength, DWORD* pdwBytesReceived, WINHTTP_WEB_SOCKET_BUFFER_TYPE* pBufferType);
// Send data to the WebSocket server
DWORD Send(WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType, void* pBuffer, DWORD dwLength);
// Close the connection to the server
DWORD Close(WINHTTP_WEB_SOCKET_CLOSE_STATUS status, CHAR* reason = NULL);
// Retrieve the close status sent by a server
DWORD QueryCloseStatus(USHORT* pusStatus, PVOID pvReason, DWORD dwReasonLength, DWORD* pdwReasonLengthConsumed);
// Free resources
VOID Free();
};
}
#endif // !WINHTTP_WEB_SOCKET_CLIENT_H