Fix issue #20: type cast in send(), add WSAStartup, and add CRTSECURE_NO_WARNINGS for MSVC2013.
This commit is contained in:
+3
-1
@@ -1,6 +1,8 @@
|
|||||||
#include "easywsclient.hpp"
|
#include "easywsclient.hpp"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
// CRTSECURE_NO_WARNINGS for sscanf errors in MSVC2013 Express
|
||||||
|
#define CRTSECURE_NO_WARNINGS
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
@@ -203,7 +205,7 @@ class _RealWebSocket : public easywsclient::WebSocket
|
|||||||
while (txbuf.size()) {
|
while (txbuf.size()) {
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ret = ::send(sockfd, (int8_t*)&txbuf[0], txbuf.size(), 0);
|
ret = ::send(sockfd, (char*)&txbuf[0], txbuf.size(), 0);
|
||||||
#else
|
#else
|
||||||
ret = ::send(sockfd, &txbuf[0], txbuf.size(), 0);
|
ret = ::send(sockfd, &txbuf[0], txbuf.size(), 0);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
// g++ -std=gnu++0x example-client-cpp11.cpp -o example-client-cpp11
|
// g++ -std=gnu++0x example-client-cpp11.cpp -o example-client-cpp11
|
||||||
#include "easywsclient.hpp"
|
#include "easywsclient.hpp"
|
||||||
//#include "easywsclient.cpp" // <-- include only if you don't want compile separately
|
//#include "easywsclient.cpp" // <-- include only if you don't want compile separately
|
||||||
|
#ifdef _WIN32
|
||||||
|
#pragma comment( lib, "ws2_32" )
|
||||||
|
#include <WinSock2.h>
|
||||||
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -10,6 +14,17 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using easywsclient::WebSocket;
|
using easywsclient::WebSocket;
|
||||||
|
#ifdef _WIN32
|
||||||
|
INT rc;
|
||||||
|
WSADATA wsaData;
|
||||||
|
|
||||||
|
rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||||
|
if (rc) {
|
||||||
|
printf("WSAStartup Failed.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::unique_ptr<WebSocket> ws(WebSocket::from_url("ws://localhost:8126/foo"));
|
std::unique_ptr<WebSocket> ws(WebSocket::from_url("ws://localhost:8126/foo"));
|
||||||
assert(ws);
|
assert(ws);
|
||||||
ws->send("goodbye");
|
ws->send("goodbye");
|
||||||
@@ -22,6 +37,9 @@ int main()
|
|||||||
if (message == "world") { wsp->close(); }
|
if (message == "world") { wsp->close(); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
// N.B. - unique_ptr will free the WebSocket instance upon return:
|
// N.B. - unique_ptr will free the WebSocket instance upon return:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user