Hello everyone! I'm trying to develop AR app, using C++ server and Unity as a client. I've done simple connection using WinSock between C++ server and Unity, and it send simple string. Now I tried to add opencv to the server (The idea is: it detects the marker and sends cordinates to Unity). However, when I add opencv libriaries, the server stops to work properly (When I start the server, it immediately says that the client is connected, but the client is not started). So i have no idea, what to do. Here is a code:
#include "stdafx.h"
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#pragma comment(lib,"ws2_32.lib")
#include <WinSock2.h>
#include <iostream>
#include <string>
#include "opencv2\core.hpp"
#include "opencv2\imgcodecs.hpp"
#include "opencv2\imgproc.hpp"
#include "opencv2\highgui.hpp"
#include "opencv2\aruco.hpp"
#include "opencv2\calib3d.hpp"
#include <sstream>
#include <iostream>
#include <fstream>
using namespace std;
using namespace cv;
int main() {
WSAData wsaData;
WORD DllVersion = MAKEWORD(2, 1);
if (WSAStartup(DllVersion, &wsaData) != 0) {
MessageBoxA(NULL, "WinSock sturtup failed", "Error", MB_OK | MB_ICONERROR);
exit(1);
}
SOCKADDR_IN addr; // socket adresy
int addrlen = sizeof(addr);
addr.sin_addr.s_addr = inet_addr("100.100.0.1"); //
addr.sin_port = htons(10101);
addr.sin_family = AF_INET; //ipv4
SOCKET sListen = socket(AF_INET, SOCK_STREAM, NULL);
bind(sListen, (SOCKADDR*)&addr, sizeof(addr));
listen(sListen, SOMAXCONN);
SOCKET newConnection;
newConnection = accept(sListen, (SOCKADDR*)&addr, &addrlen);
if (newConnection == 0) {
cout << "Failed to accept the client's connection" << endl;
}
else {
cout << "Client connected!" << endl;
char MOTD[256];
string sendData;
cin >> sendData;
int i;
for (i = 0; i < sendData.length(); i++)
{
MOTD[i] = sendData.at(i);
}
send(newConnection, MOTD, i, NULL);
}
system("pause");
return 0;
}
Please Notice that code is working well (when there no opencv libs added).