B4J Question jNetwork module - Support multi threading?

avacondios

Active Member
Licensed User
Longtime User
Hi,

Using the jNetwork lib, you can initialise a server UDPSochet, or Serversocket. Calling the Listen method, it starts to listening in the background for incoming connections. Does it support a multithreading on each new incoming connection ? or it is running on the main thread ?

Also, is this an asynchronous ?

BR/Antonis
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Both UDPSocket and ServerSocket listen for connections or packets in the background. If you are using TCP sockets then you should use AsyncStreams to manage the connection. Each connection should use its own AsyncStreams object.

This way multiple connections will not block the main thread.

You can see an example of this in the CCTV example (the one that works with multiple clients).
 
Upvote 0

avacondios

Active Member
Licensed User
Longtime User
Hi Erel,

I am asking, because I want to use a map object from main thread (main module) on each new connection event. The map object , will it threadsave on the concurrent connections ? Or each new connection will run on other thread (except from main) and I will have issues ?
 
Upvote 0
Top