Force libwebrtc to use TCP

117 views
Skip to first unread message

Dev

unread,
Sep 5, 2025, 10:36:42 AMSep 5
to discuss-webrtc
Hi everyone,

I'm trying to connect two peers (a client and a server) using libwebrtc.

The client can only make outbound TCP connections (UDP blocked), so I am forced to communicate using TCP.

Additionally I want to avoid adding a TURN relay in the middle because it complicates things.

My plan is to create a raw TCP socket (or maybe WebSocket connection) between client and server, and transparently send all the libwebrtc payloads over it, rather than relying on libwebrtc for networking.

The right terminology would be "sans IO", where libwebrtc lets the application developer handle the part of transmitting packets.

Can anyone offer pointers on how to achieve this? I vaguely know that I must override some classes like PortAllocator and perhaps Socket. Are there any others?

Thanks!

guest271314

unread,
Sep 6, 2025, 12:47:56 PMSep 6
to discuss-webrtc
Technically, in Chromium-based browsers, libwebrtc doesn't have to be used at all to create raw TCP connections. 

It's possible to create an Isolated Web App where Direct Sockets TCPSocket is defined globally, and thereafter make direct TCP socket connections. See https://github.com/guest271314/sockets/tree/fetch-webrtc

Philipp Hancke

unread,
Sep 6, 2025, 12:58:55 PMSep 6
to discuss...@googlegroups.com
ice-tcp should work between native libwebrtc clients (browsers don't listen).

Rerouting packets internally is way more complicated than colocating a small TURN server with the server.

--
This list falls under the WebRTC Code of Conduct - https://webrtc.org/support/code-of-conduct.
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/discuss-webrtc/5e92a139-4f0f-40d3-9bda-975337c250acn%40googlegroups.com.

Dev

unread,
Sep 7, 2025, 11:24:45 AMSep 7
to discuss-webrtc
Thanks for your answer but I should mention the client is a native application, therefore I am working with pure libwebrtc, not browser APIs.

shakeeb nazmus

unread,
Sep 9, 2025, 1:36:38 AM (13 days ago) Sep 9
to discuss-webrtc
>>I'm trying to connect two peers (a client and a server) using libwebrtc.

If NAT traversal is required between the two peers, it will be quite challenging. Otherwise, it can be achieved by modifying the native code.

"NAT traversal is required" means that both peers are located behind separate NATs.

Thanks,

Shakeeb

Dev

unread,
Sep 9, 2025, 10:55:24 AM (13 days ago) Sep 9
to discuss-webrtc
> If NAT traversal is required between the two peers, it will be quite challenging. Otherwise, it can be achieved by modifying the native code.

The easiest way to solve my issue (without libwebrtc) is simply by creating an outbound WebSocket from the client to the server, and exchanging data through that. But I'd like to continue using libwebrtc across the board instead of having multiple implementations

Could you please elaborate on how to modify the native code? I know some classes have to be overridden to replace the low-level networking layer, but the problem is the sheer number of classes libwebrtc has

Thanks,
Dev

Dev

unread,
Sep 9, 2025, 10:55:58 AM (13 days ago) Sep 9
to discuss-webrtc
> Rerouting packets internally is way more complicated than colocating a small TURN server with the server.
Yes I'm already using coturn for this, but I want to get direct connection working and move away from TURN

> ice-tcp should work between native libwebrtc clients

Thanks, I didn't know ICE also worked over TCP

However, it seems to only gather TCP candidates for the private IP. I ran a simple libwebrtc binary on a cloud VM. These are the ICE candidates that were generated (TCP in bold):

candidate:1235164123 1 udp 2122260223 172.18.0.1 52875 typ host generation 0 ufrag ATvl network-id 1 network-cost 50
candidate:1037470997 1 udp 2122194687 172.31.15.109 39118 typ host generation 0 ufrag ATvl network-id 2 network-cost 50
candidate:2459724843 1 udp 1685987071 1.2.3.4 39118 typ srflx raddr 172.31.15.109 rport 39118 generation 0 ufrag ATvl network-id 2 network-cost 50
candidate:1602376041 1 udp 1686052607 1.2.3.4 52875 typ srflx raddr 172.18.0.1 rport 52875 generation 0 ufrag ATvl network-id 1 network-cost 50
candidate:928053571 1 tcp 1518280447 172.18.0.1 44865 typ host tcptype passive generation 0 ufrag ATvl network-id 1 network-cost 50
candidate:1125740429 1 tcp 1518214911 172.31.15.109 59879 typ host tcptype passive generation 0 ufrag ATvl network-id 2 network-cost 50

As you can see, all the TCP candidates have the private IP
  • The VM has a public IP (1.2.3.4)
  • All incoming/outgoing TCP ports are open to the internet
  • Firewall is disabled
Is there any way to tell libwebrtc that it can listen on the public IP using TCP?
Reply all
Reply to author
Forward
0 new messages