forked from Astienth/bhaptics_protube_udpServer_Csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (52 loc) · 2.1 KB
/
Program.cs
File metadata and controls
59 lines (52 loc) · 2.1 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Net.Sockets;
using System.Net;
using System.Text;
namespace bHapticsServer
{
internal static class Program
{
private const int UdpPort = 5015;
public static TactsuitVR tactsuitVR;
private static void Main()
{
tactsuitVR = new TactsuitVR();
CreateUdpServer();
}
private static void CreateUdpServer()
{
using (var udpServer = new UdpClient(new IPEndPoint(IPAddress.Loopback, UdpPort)))
{
Console.WriteLine($"UDP Server started listening on 127.0.0.1:{UdpPort}");
while (true)
{
var remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
var receivedBytes = udpServer.Receive(ref remoteEndPoint);
var receivedText = Encoding.UTF8.GetString(receivedBytes);
HandleMessage(receivedText);
}
}
// ReSharper disable once FunctionNeverReturns
}
private static void HandleMessage(string message)
{
Console.WriteLine($"Received message: {message}");
if(message.Contains(","))
{
var parameters = message.Split(',');
var effectKey = parameters[0];
var intensity = float.TryParse(parameters[1], out var intensityResult) ? intensityResult : 1f;
var duration = float.TryParse(parameters[2], out var durationResult) ? durationResult : 1f;
var offsetX = float.TryParse(parameters[3], out var offsetXResult) ? offsetXResult : 0;
var offsetY = float.TryParse(parameters[4], out var offsetYResult) ? offsetYResult : 0;
TactsuitVR.PlaybackHaptics(effectKey, intensity, duration, offsetX, offsetY);
Console.WriteLine($"Playing effect with parameters: {message}");
}
else
{
TactsuitVR.PlaybackHaptics(message);
Console.WriteLine($"Playing effect: {message}");
}
}
}
}