Hi,
We are trying to talk to vMix and replay using the HTTP Web API and aren't having any luck yet. Is there some sample code available that could guide us? Here is what we've tried... Any ideas would be much appreciated. - Mike
/////////////////////////////////////////////////////
// Here's some code I found and massaged from
// stackoverflow.com that I use to connect to a URL
// and send a command string.
//
#include <windows.h>
#include <string>
#include <stdio.h>
using std::string;
#pragma comment(lib,"ws2_32.lib")
void ParseUrl( char *mUrl, string &serverName, WORD& portNum, string &command )
{
string::size_type n;
string url = mUrl;
if (url.substr(0,7) == "http://")
url.erase(0,7);
if (url.substr(0,8) == "https://")
url.erase(0,8);
n = url.find('/');
if (n != string::npos)
{
serverName = url.substr(0,n);
command = url.substr(n + 1);
}
else
{
serverName = url;
command = "";
}
n = serverName.find(":");
if ( n != string::npos )
{
string portNumStr = url.substr(n + 1);
serverName = url.substr(0,n);
portNum = atoi( portNumStr.c_str() );
}
else
{
portNum = 80; // standard port number
}
}
SOCKET connectToServer(char *szServerName, WORD portNum)
{
struct hostent *hp;
unsigned int addr;
struct sockaddr_in server;
SOCKET conn;
conn = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (conn == INVALID_SOCKET)
return NULL;
if(inet_addr(szServerName)==INADDR_NONE)
{
hp=gethostbyname(szServerName);
}
else
{
addr=inet_addr(szServerName);
hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);
}
if(hp==NULL)
{
closesocket(conn);
return NULL;
}
server.sin_addr.s_addr=*((unsigned long*)hp->h_addr);
server.sin_family=AF_INET;
server.sin_port=htons(portNum);
if(connect(conn,(struct sockaddr*)&server,sizeof(server)))
{
closesocket(conn);
return NULL;
}
return conn;
}
int SendAPICommand( char* szCommand )
{
string server, command;
WORD portNum;
WSADATA wsaData;
SOCKET conn;
if ( WSAStartup(0x101, &wsaData) != 0)
return -1;
ParseUrl( szCommand, server, portNum, command);
conn = connectToServer( (char*)server.c_str(), portNum );
if ( conn != NULL )
{
const char* pszCommand = command.c_str();
send(conn, pszCommand, strlen(pszCommand), 0);
closesocket(conn);
}
WSACleanup();
return 0;
}