-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCPMessages4OBS_testclient.ps1
38 lines (34 loc) · 1.02 KB
/
TCPMessages4OBS_testclient.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Function Send-TCPMessage {
Param (
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
[string]
$EndPoint
,
[Parameter(Mandatory = $true, Position = 1)]
[int]
$Port
,
[Parameter(Mandatory = $true, Position = 2)]
[string]
$Message
)
Process {
# Setup connection
$IP = [System.Net.Dns]::GetHostAddresses($EndPoint)
$Address = [System.Net.IPAddress]::Parse($IP)
$Socket = New-Object System.Net.Sockets.TCPClient($Address, $Port)
# Setup stream wrtier
$Stream = $Socket.GetStream()
$Writer = New-Object System.IO.StreamWriter($Stream)
# Write message to stream
$Message | ForEach-Object {
$Writer.WriteLine($_)
$Writer.Flush()
}
# Close connection and stream
$Stream.Close()
$Socket.Close()
}
}
#Send-TCPMessage -Port 29800 ` -Endpoint 127.0.0.1 -message "=StartVirtualCam"