But I'm stuck with the connect-function, how is that struct supposed to look? What should it include? Why that pointer? ...?
1 2
int connect(int sockfd, conststruct sockaddr *addr,
socklen_t addrlen);
Could someone explain that code?
Also, I've already written this piece for the sockets:
1 2 3 4 5 6 7 8 9
//Engine for socket
int socket_a = socket(AF_INET, SOCK_STREAM, 0);
//Connect? - Help needed
if (socket_a == -1) {
cout<<"An error occured in the connection"<<endl;
} else {
cout<<"Connection succesful"<<endl;
}
//End - Engine for socket
it's a pointer to sockaddr because the socket library is using a form of OOP: sockaddr is the "base class", and the actual data members and the size of the structure depend on the value of addr->sa_family
Since you're using AF_INET, you need to create an object of type struct sockaddr_in, fill what's needed, and pass a pointer to that into connect()