B4J Question Multithreaded pop3 server

wl

Well-Known Member
Licensed User
Longtime User
As I understand from a previous post: most of the code in B4J is executed on a single thread (except for example the webserver implementation).

I would like to create a custom POP3 server (the protocol is very easy and I already have written the B4J code for it). To be production-safe it seems this kind of server should be written in a multithreaded way, so that a single connection can't block other connections.

Is there anyway way to do so in B4J ? I already though (as a workaround) to spawn different processes for each connection, but this is:
1. ugly
2. hard to implement as only a single process can listen on a specific TCP port.

Thanks for any hints.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
All the network related code, assuming that you are using AsyncStreams, is executed by background threads.
This means that only your code runs on the main thread. The slow parts (the network operations) are already multithreaded.

Managing multiple AsyncStreams and sockets is not trivial. You can see an example here: https://www.b4x.com/android/forum/threads/b4j-cctv-example.34695/#post-203347
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
All the network related code, assuming that you are using AsyncStreams, is executed by background threads.
This means that only your code runs on the main thread. The slow parts (the network operations) are already multithreaded.

Managing multiple AsyncStreams and sockets is not trivial. You can see an example here: https://www.b4x.com/android/forum/threads/b4j-cctv-example.34695/#post-203347

Thanks Erel. Problem is that the idea is to have some kind of passthrough in the POP3 server to another server, which would mean that my B4J code could take a while to execute (also network related communication)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Problem is that the idea is to have some kind of passthrough in the POP3 server to another server, which would mean that my B4J code could take a while to execute (also network related communication)
It is not a problem at all as all the network related libraries are already multithreaded. The main thread will not be delayed while your server calls another server.
 
Upvote 0
Top