communication between emscripten socket and posix socket

341 views
Skip to first unread message

Nathan M

unread,
Jun 20, 2022, 9:03:54 AM6/20/22
to emscripten-discuss
Hi, 

I am trying the communication between Posix's UDP server & emscripten 's client.

i.e both uses almost same POSIX socket APIs

Posix's UDP server - Compiled with LINUX GCC 

 emscripten 's client - compiled with emcc tool

 Both the applications are sending message through sendto() is success. But other client is not receiving them. What would be the issue ?

Do we have any sample code ?

Floh

unread,
Jun 21, 2022, 5:24:30 AM6/21/22
to emscripten-discuss
The Socket API in Emscripten is a wrapper around WebSockets, not POSIX sockets. From the source code side it looks and behaves roughly like a non-blocking POSIX socket, but the underlying protocol is WebSocket, and incompatible to TCP or UDP, meaning you can't connect to a native TCP or UDP port, only to a WebSocket port.

To connect to a TCP port, you'll need a WebSocket-to-TCP proxy on the server-side like Gorilla WebSocket (https://github.com/gorilla/websocket) or Websockify (https://github.com/novnc/websockify).

I'm not aware of a WebSocket to UDP proxy though, instead AFAIK for UDP connections, the recommended solution is to use a higher level networking library which sits on top of WebRTC data channels, like ENet or HumbleNet.

Reply all
Reply to author
Forward
0 new messages