logo

Live Production Software Forums


Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
MikeBenke  
#1 Posted : Monday, May 21, 2018 1:37:54 AM(UTC)
MikeBenke

Rank: Advanced Member

Groups: Registered
Joined: 2/7/2018(UTC)
Posts: 45
Location: Saint Louis

Thanks: 4 times
Was thanked: 4 time(s) in 3 post(s)
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;
}
stigaard  
#2 Posted : Monday, May 21, 2018 1:53:04 AM(UTC)
stigaard

Rank: Advanced Member

Groups: Registered
Joined: 5/20/2015(UTC)
Posts: 493
Man
Denmark
Location: Copenhagen, Denmark

Thanks: 398 times
Was thanked: 100 time(s) in 79 post(s)
If you use JavaScript, i have created a utility library that you can use. https://www.npmjs.com/package/vmix-js-utils
thanks 1 user thanked stigaard for this useful post.
MikeBenke on 5/21/2018(UTC)
MikeBenke  
#3 Posted : Monday, May 21, 2018 2:10:41 AM(UTC)
MikeBenke

Rank: Advanced Member

Groups: Registered
Joined: 2/7/2018(UTC)
Posts: 45
Location: Saint Louis

Thanks: 4 times
Was thanked: 4 time(s) in 3 post(s)
Thanks Stigaard, we'll check it out. Our code base is in C++, but maybe Adam will get some ideas from your library..
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.