So after I got the problems here done, I encountered a new one :(
What I am trying to do:
I want to stream a camera frame to a certain IP/URL and be able to open it through a browser in the same network - using send() to get the images to the connected socket.
Problem:
The streaming itself works when I enter the IP in my browser without any problems, however when the IP is entered from another device in the same network the camera images itself get transmitted super slowly (the program stutters itself -> i'm showing images of the camera itself when someone connects and it starts getting slow once it's from another device).
Once the other device cuts the connection (aka closes the tab where the IP has been entered) the camera/application works just fine again.
Can the data transmission be slowing down the programm itself so much as well? Or what might be the reason for that?
Here's the server part I'm using (got most of it from a tutorial):
// initialize winsock
rc=WSAStartup(MAKEWORD(2,0),&wsa);
if(rc!=0)
{
printf("Error: startWinsock, Errorcode: %d\n",rc);
return 1;
}
else
{
printf("Winsock initialized!\n");
}
// Create socket
acceptSocket=socket(AF_INET,SOCK_STREAM, IPPROTO_IP);
if(acceptSocket==INVALID_SOCKET)
{
printf("Error: Socket-Creation failed, Errorcode: %d\n",WSAGetLastError());
return 1;
}
else
{
printf("Socket succesfully created!\n");
}
memset(&addr,0,sizeof(SOCKADDR_IN));
addr.sin_family=AF_INET;
addr.sin_port=htons(1234);
addr.sin_addr.s_addr=ADDR_ANY;
rc=bind(acceptSocket,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));
if(rc==SOCKET_ERROR)
{
printf("Error: bind, Errorcode: %d\n",WSAGetLastError());
return 1;
}
else
{
printf("Socket bound to port 1234\n");
}
rc=listen(acceptSocket,10);
if(rc==SOCKET_ERROR)
{
printf("Error: listen, Errorcode: %d\n",WSAGetLastError());
return 1;
}
else
{
printf("acceptSocket is now in listen mode...\n");
}
for(i=0; i<MAX_CLIENTS; i++)
{
clients[i]=INVALID_SOCKET;
}
SOCKET connectedSocket=accept(acceptSocket,NULL,NULL);
if(connectedSocket==INVALID_SOCKET)
{
printf("Error, Errorcode: %d\n",WSAGetLastError());
return 1;
}
else
{
printf("New connection accepted!\n");
}
//socket stuff end
I'm also trying to get a multi-client access working and currently have no idea how to implement it in the code I have. I tried following some tutorials (e.g. http://www.binarytides.com/code-tcp-socket-server-winsock/) but it didn't work for me so far.