leaningtech / cheerpj-meta

Run Java 8 applications, libraries, applets, Java Web Start, and Oracle Forms on the web without legacy plugins.
https://labs.leaningtech.com/cheerpj
434 stars 21 forks source link

TCP sockets do not work #143

Closed ddyer0 closed 2 years ago

ddyer0 commented 2 years ago

As far as I can tell, opening a tcp socket (to the http host, on a different port) seems to work, but writing to the socket throws an unexpected NullPointerException. Here's the log

LoadThread 47+764.000 classForName online.game.Game LoadThread 47+766.000 classForName online.game.Game Lobby for guest 47+890.000 opened socket Socket[addr=local.boardspace.net/127.0.0.1,port=2255,localport=0] Writer 48+101.000 realSendMessage java.net.SocketOutputStream@900 200 0 guest#3 223.16.11.163 0 N 3 Writer 48+101.000 got bytes [B@901 40 Writer 48+101.000 part 1 Writer 48+101.000 Part2 Writer 48+101.000 tcp write java.net.SocketOutputStream@900 [B@902 0 52 Writer 48+115.000 Unusual write error java.lang.NullPointerException java.net.SocketOutputStream@900 200 0 guest#3 223.16.11.163 0 N 3 cheerpOS.

this is from a working app where the code has been in use for years, so I'm sure the exception is not correct.

ddyer0 commented 2 years ago

Stumbling through the debugger with a test program, I encountered this: `function cheerpNetConnectSocket(fds, fd, ipAddr, ipPort, p) { var a={p:p,f:cheerpNetConnectSocket,pc:0,fileDesc:null}; if(cjNetProxy == null) { assert(ipPort == 80); return 0; } if(fd < 0)

..it looks like ports other than 80 are not allowed, or is there some magic I need to?

alexp-sssup commented 2 years ago

Raw TCP sockets are simply not supported by browsers, CheerpJ cannot support them out-of-the-box. Please note that WebSockets are not sockets, which is always a source of great confusion.

The code you stumbled upon is experimental, and designed to support third-party HTTP libraries by decoding requests over the wire and repackaging them as fetch requested by the browser. The port == 80 assertion is too strict and will be eventually removed, but anyway it's not fatal.

In your case I believe you are attempting to use raw sockets, so this code won't work for you anyway.

ddyer0 commented 2 years ago

Back in the day, java applets were able to use tcp sockets, and java web start apps can still do so. What approach do you recommend to get tcp sockets functionality, if some reworking of the java code is allowed?