Hi guys. Hopefully I’ll be able to explain this situation
So. I have one PC with my APP that will serve as a server for some clients in the LAN. When this server (my app) will receive some request from some client, it will do a call to some dll (via COM instance etc) and this dll will give back some result, after which the server will hand back the results to the client who called it. The call to dll is synchronous - server issues a call and waits for the result (few seconds).
Now idea is this: I use nettalk’s NetWholePackets to issue a call from client to server and back.
So the flow:
- Client sends tcp request to server.
- Server (nettalk procedure) gets the request, checks the local queue if this client has connected before. If yes, returns just “BUSY”. Done. If not, it adds this client to the queue.
- After adding the client to the queue, it calls the “DLLprocedure” (passing params) which does the toDLL call.
- DLLProcedure waits for dll results and sends them back to nettalk procedure.
- Nettalk procedure, based on the local queue, returns results to the client and deletes the record in the queue.
Now the issue about sync and threads etc. If there was one client, it would be simple - call after call after call and back. But it’s not. So while server is waiting for dll data, some other client might wanna send a new request etc. So I need to keep things between clients and server in sort of async.
So, the idea: Server runs the nettalk procedure (netWholePacket class) on it’s own thread, waiting for requests. When request happens, it has to START the “DLLprocedure” because this one can take time and I must not block the nettalk procedure in processing. But if I do that, then the “DLLProcedure” must do some callback when it’s done. And the call back should actually be to the nettalk procedure, where I keep my queue with “busy” clients list, because nettalk proc needs to return data to the right client.
So I thought ok: request from client comes in, I check the queue, add a record to it with new guid. I START the dllproc passing guid and original request. dllproc starts, calls dll, gets back some data.
Now I’m stuck. How do I send back dll-data+original guid to the nettalk proc which started dll-proc? I need to get back so I can check my queue for guid and send that dll-data back to the right client (and delete the record in the queue)?
AFAIK START’ed procedures cannot return anything. I cannot use NOTIFY back because my GUID and DLL-DATA are both STRINGs.
Did I go in the right way for this? Am I thinking ok trying to keep my nettalk “server” proc free of some calls that would make it stuck, even for a short while? I’m thinking it’s a good idea to START that dll-proc for every client request, make it run in it’s own thread, initiating COM and all that stuff. You know, to keep things thread-safe sort of.
Geez, I hope this makes sense, appreciate the help.
Bostjan