vMix Forums
»
General
»
General Discussion
»
Questions concerning the TCP API
Rank: Advanced Member
Groups: Registered
Joined: 4/16/2013(UTC) Posts: 406 Location: Iowa Thanks: 281 times Was thanked: 32 time(s) in 29 post(s)
|
So I've used the Web API, but was unaware of the TCP API until this week. I'm attempting to use it, but am confused! What are you sending the commands with? A browser? script code? In a browser, all I get is a search response. It's obvious I am misinterpreting the information provided. I had been using Autohotkey to send commands via web commands to vMix, but if the TCP API is more efficient, its obviously the way to go. Just need a little push in the right direction to get started.
Can anyone give me a push?
|
|
|
|
Rank: Member
Groups: Registered
Joined: 8/4/2015(UTC) Posts: 17 Thanks: 3 times Was thanked: 8 time(s) in 4 post(s)
|
First you need to connect to vMix using TCP protocol. Then transmit the command in UTF-8 format. Also check the answer from the sent command success or error.
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 4/16/2013(UTC) Posts: 406 Location: Iowa Thanks: 281 times Was thanked: 32 time(s) in 29 post(s)
|
So what are you using to transmit/connect?
|
|
|
|
Rank: Member
Groups: Registered
Joined: 8/4/2015(UTC) Posts: 17 Thanks: 3 times Was thanked: 8 time(s) in 4 post(s)
|
TCP connection example
client.Connect("127.0.0.1", 8099); NetworkStream stream = client.GetStream(); Byte[] readingData = new Byte[1024]; String responseData = String.Empty; StringBuilder completeMessage = new StringBuilder(); int numberOfBytesRead = 0; do { numberOfBytesRead = stream.Read(readingData, 0, readingData.Length); completeMessage.AppendFormat("Answer: {0}", Encoding.UTF8.GetString(readingData, 0, numberOfBytesRead)); } while (stream.DataAvailable); responseData = completeMessage.ToString(); textBox1.Text = responseData;
Example of TCP transfer vMix command
textBox1.Text = ""; Byte[] data = Encoding.UTF8.GetBytes("FUNCTION OverlayInput1Out\r\n"); NetworkStream stream = client.GetStream(); stream.Write(data, 0, data.Length); Byte[] readingData = new Byte[1024]; String responseData = String.Empty; StringBuilder completeMessage = new StringBuilder(); int numberOfBytesRead = 0; do { numberOfBytesRead = stream.Read(readingData, 0, readingData.Length); completeMessage.AppendFormat("Answer: {0}", Encoding.UTF8.GetString(readingData, 0, numberOfBytesRead)); } while (stream.DataAvailable); responseData = completeMessage.ToString(); textBox1.Text = responseData;
|
3 users thanked Stealth77 for this useful post.
|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/6/2021(UTC) Posts: 8 Location: Münster
|
Could anybody explain me how to use this example, please. I tried to put it in Visual Studio 2022 to make a consoleaplication in C++ and in C# without success. Or could somebody translate this in Visual Basic. From the user guide I took: Example Request: FUNCTION PreviewInput Input=5\r\n and changed it to FUNCTION Play Input 1\r\n In Visual Basic I try Code:Imports System.Net.Sockets
Imports System.IO
Module Module1
Dim stream As NetworkStream
Dim streamw As StreamWriter
Dim streamr As StreamReader
Dim client As New TcpClient
Dim strBefehl As String
Sub Main()
strBefehl = "FUNCTION Play Input 1\r\n"
Try
client.Connect("127.0.0.1", 8099)
If client.Connected Then
stream = client.GetStream
streamw = New StreamWriter(stream)
streamr = New StreamReader(stream)
streamw.WriteLine(encode(strBefehl))
Console.WriteLine(encode(strBefehl))
Console.WriteLine(strBefehl)
streamw.Flush()
Console.WriteLine(Receive)
client.Close()
stream.Close()
streamw.Close()
streamr.Close()
Else
Console.WriteLine("Not connected")
End If
Catch
Console.WriteLine("gar nicht connected")
End Try
End Sub
Function Receive() As String
Try
Return streamr.ReadLine
Catch
Return ""
End Try
End Function
Function encode(ByVal str As String) As String
'supply True as the construction parameter to indicate
'that you wanted the class to emit BOM (Byte Order Mark)
'NOTE: this BOM value is the indicator of a UTF-8 string
Dim utf8Encoding As New System.Text.UTF8Encoding(True)
Dim encodedString() As Byte
encodedString = utf8Encoding.GetBytes(str)
Return utf8Encoding.GetString(encodedString)
End Function
End Module
and I got an answer from vMix: FUNCTION Play Input 1\r\n FUNCTION Play Input 1\r\n VERSION OK 26.0.0.40 but the video in 1 did not start Thank you Martin
|
|
|
|
Rank: Advanced Member
Groups: Registered
Joined: 2/23/2019(UTC) Posts: 561
Thanks: 62 times Was thanked: 131 time(s) in 119 post(s)
|
Originally Posted by: MDB From the user guide I took: Example Request: FUNCTION PreviewInput Input=5\r\n and changed it to FUNCTION Play Input 1\r\n
Shouldn't it be "FUNCTION Play Input=1\r\n" then?
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/6/2021(UTC) Posts: 8 Location: Münster
|
Oh yes, you are right (it was too late) I will give it a try
Thank you
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/6/2021(UTC) Posts: 8 Location: Münster
|
I tried "FUNCTION Play Input=1\r\n" and "FUNCTION=Play Input=1\r\n" and also "FUNCTION PreviewInput Input=1\r\n" without success (http://http://127.0.0.1:8088/API/?Function=Play&Input=1 works)
Shows this line "VERSION OK 26.0.0.40" that a connection to VMix was established?
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 7/6/2021(UTC) Posts: 8 Location: Münster
|
Finally I succeded to start the video in input 1 with: strBefehl = "FUNCTION Play Input=1" & vbCrLf
|
|
|
|
vMix Forums
»
General
»
General Discussion
»
Questions concerning the TCP API
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.
Important Information:
The vMix Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close