I guess I'm experiencing brain freeze or something, having gotten bogged down in the various facets of the task, so I'm asking for suggestions / experiences / pitfalls to avoid / etc. in writing the server side of a client-server application for Linux.
I had written a simple server in this fashion:
Sock := fpSocket (AF_INET,SOCK_STREAM,0);
SAddr.sin_family := AF_INET;
SAddr.sin_port := htons(SolvPort);
SAddr.sin_addr.s_addr := 0;
if (fpBind (Sock,@SAddr,sizeof(saddr)) = -1) then
begin
(exit);
end;
if (fpListen (Sock,1) = -1) then
PError ('Solver : Listen : ');
while (running) do
begin
if (not Accept (Sock,SrcAddr,Sin,Sout)) then
PError ('Solver : Accept : '+NetAddrToStr(SrcAddr.sin_addr));
SRD[ind].FIn := Sin;
SRD[ind].FOut := Sout;
SRD[ind].SrcAddy := SrcAddr;
ptr := @SRD[ind];
BeginThread (@ClientRun,ptr);
...
end
(various details omitted)
I had never stress tested it, but it seemed to work fine. Then I discovered that a socket error (e.g. the client side program exiting prematurely) would blow out the server program. (Small twinge of cold in the brain here.) Then I realized that I ought to spawn a process rather than a thread because of the various/unknown errors that might creep into the ClientRun routines - a small but growing set of code.
So now the local databases (not shown) which I was going to access to keep client data and IP-data for filtering now needs to be multi-process capable. (Brain got chilly.)
I then learned that instead of knowing the ClientRun routines being done in several seconds, they instead ~might~ take an hour or more in some cases, so I had to prepare to disconnect nicely and reconnect later, picking up the results after re-login. (Brain starting to numb up.) (I can figure out the data pick-up code, after I get my bearings with the rest of it.)
I likewise cannot pass network handles through a calling sequence hack, but have to pass them some other way. (Brain froze here.)
I'll have MySQL available on the server this code is destined for, but I was hoping to use a local (on machine) database of sorts (I have my own I had planned to use) to keep things fast.
Can anyone give me pointers, suggested design, examples, etc.?
Thank you.
Walter