0

I want to read an obj ninja stream in c#. I've read, that it is an UDP stream.

I'm very inexperienct whith Networking and Socket programming, so please feel free to suggest completely different approaches.

My Idea so far: I have a function ReceiveSocket() which ist run in a new Thread:

Thread t = new Thread(ReceiveSocket);
    t.Start();

void ReceiveSocket()
{
    Uri myUri = new Uri(URL);
    IPAddress ip = Dns.GetHostAddresses(myUri.Host)[0];

    IPEndPoint RemoteIpEndPoint = new IPEndPoint(ip, 48001);

    Socket socket = new Socket(RemoteIpEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Udp);
    socket.Bind(RemoteIpEndPoint);
    Debug.Log("Starting....");
    while(true)
    {
        byte[] data = new byte[1024];
        int received = socket.Receive(data);
        Debug.Log("Received");
    }
}

The URL is something like this: https://vdo.ninja/?view=2E7iCUg (just go on obs ninja and stream some Application, Monitor or Webcam)

But already in the Construction of the Socket (in ReceiveSocket()) is an Error thrown.

What I want to do: Read a Video Stream (in this example an obj ninja stream) and display each frame to a texture in Unity.

Thanks for your Help

Ecko
  • 5
  • 2
  • Tip: spinning up a thread just to perform I/O (and spends most of its time waiting) is kinda a waste of a thread. Consider using contemporary alternatives such as that usable via `async/await`. e.g. `UdpClient.BeginReceive` in conjunction with this [pattern](https://stackoverflow.com/a/30401146/585968). –  Oct 04 '22 at 10:26
  • Looks like you try to bind your socket on the *remote* endpoint, which is obviously not possible, unless you are connecting to your own host. `Bind` is used to bind your socket to a *local* endpoint. You have to take the local endpoint which is used for traffic with the outside world (if you have multiple IPs). – Holger Böhnke Oct 05 '22 at 07:58

0 Answers0