There is code for a simple server on a socket
When launched, the program ends with the message “Error: Ucan’t accept client connection: 10022”.
If you remove the opencv header, then everything works correctly. What could be causing the error?
#include <iostream>
#include <fstream>
#include <string>
#include <WS2tcpip.h>
#include <opencv2/core/core.hpp>
#pragma warning(disable: 4996)
#pragma comment(lib, "ws2_32.lib")
using namespace std;
int main() {
const char* ip = "127.0.0.1";
int port = 1111;
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 1), &wsaData) != 0) { // lib init
cout << "Error: can't init winsockn";
return -1;
}
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = inet_addr(ip);
int clientSize = sizeof(addr);
SOCKET listening = socket(AF_INET, SOCK_STREAM, NULL);
bind(listening, (SOCKADDR*)&addr, sizeof(addr));
listen(listening, SOMAXCONN);
cout << "Server startedn";
SOCKET clientSocket = accept(listening, (SOCKADDR*)&addr, &clientSize);
if (clientSocket == INVALID_SOCKET) {
cout << "Error: can't accept client connection: " << WSAGetLastError() << endl;
return -1;
}
cout << "Client connectedn";
return 0;
}
I need to start the server, accept the image and then display it on the screen. But when connecting opencv the socket stops working.
New contributor
scroptnik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.