I am trying to to learn how to stream image frames via UDP in C++ and I was following this tutorial for the server part to receive my frames, this tutorial clearly uses code from question stackoverflow question. However, after following up both sources, whenever I attempt to load my libraries in geany/c++:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
#define width 320
#define height 240
int imgSize;
int bytes=0;
bool running = true;
char key;
const int ah = 230400;
int main(int argc, char * argv[]) {
SOCKET server;
SOCKADDR_IN addr;
server = socket(AF_INET, SOCK_STREAM, 0);
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_family = AF_INET;
addr.sin_port = htons(9999);
connect(server, (SOCKADDR *)&addr, sizeof(addr));
return 0;
}
This gives me the following errors:
/home/pi/Documentos/cam.cpp: In function ‘int main(int, char**)’:
/home/pi/Documentos/cam.cpp:27:2: error: ‘SOCKET’ was not declared in this scope
27 | SOCKET server;
| ^~~~~~
/home/pi/Documentos/cam.cpp:28:2: error: ‘SOCKADDR_IN’ was not declared in this scope
28 | SOCKADDR_IN addr;
| ^~~~~~~~~~~
/home/pi/Documentos/cam.cpp:29:2: error: ‘server’ was not declared in this scope; did you mean ‘servent’?
29 | server = socket(AF_INET, SOCK_STREAM, 0);
| ^~~~~~
| servent
/home/pi/Documentos/cam.cpp:30:2: error: ‘addr’ was not declared in this scope
30 | addr.sin_addr.s_addr = inet_addr("127.0.0.1");
| ^~~~
/home/pi/Documentos/cam.cpp:30:25: error: ‘inet_addr’ was not declared in this scope; did you mean ‘in6_addr’?
30 | addr.sin_addr.s_addr = inet_addr("127.0.0.1");
| ^~~~~~~~~
| in6_addr
/home/pi/Documentos/cam.cpp:33:19: error: ‘SOCKADDR’ was not declared in this scope
33 | connect(server, (SOCKADDR *)&addr, sizeof(addr));
| ^~~~~~~~
/home/pi/Documentos/cam.cpp:33:29: error: expected primary-expression before ‘)’ token
33 | connect(server, (SOCKADDR *)&addr, sizeof(addr));
Forgive my ignorance, I'd like to know what is the right way to create a UDP socket for a specific IP/Port