WinSock, Accept(), TSocket.. etc..
Posted on 2004-08-03
What I am needing is this..
When someone connects to my server.
I accept, but I need that connection forked into two.
NewSock := accept(code,code,code);
NewSock2 := accept(code,code,code);
Where i can get two TSocket Handles for the same connection.
So, I can send(FirstTSock)/ recv(FirstTSock);
but then use send(SecondTSock,code,code,code) / recv(SecondTSock,code,code,code);
to send/recv to the same client without the firsttsock seeing the SecondTSock.
The socket is shared between two applications and what I want to do is pause the send/recv of one
application and let the other application start to send/recv on the same port to the same client.
The applications that are loaded take the socket handle and start to recv/send to the client, but is there a way I could do two tsockets that point to the same client
I am having a hard time explaining what I want, cause it is kind of confussing to me on how I want this.
Okay last attempt to exaplain what I want..
I want to pause the send/recv of the socket to the first createprocess while the second createprocess is running then restore the send/recv to the first createprocess after the second createprocess has quit. They are two different applications that are loaded and each of them take the tsocket as a param to take over the send/recv. I don't have the source to the programs my application runs and I can't quit the first process, the firstprocess has to be running, before and after I create the secondprocess. Is there a way to generate a tsocket that the second program can exclusivly have that will point back to the client app without the firstcreateprocess being about to recv/send to the client?
When I run the second program it outputs to the client, but it doesn't recv input from the client. The first program still recieves the input.
Here is what I have as code..
if CreateProcess(nil, PChar(AppParams), nil, nil, True, CREATE_NEW_CONSOLE, nil, PChar(AppPath), SI, PI) then begin
Result1 := WaitForSingleObject(PI.hThread, 100);
if fileexists('c:\rg\games\load\amb.txt') then begin
AppPath := 'c:\rg\utils\gamesrv2\ambv4';
AppParams := 'c:\rg\utils\gamesrv2\ambv4\amblaunch.exe /n 1 /d C:\RG\TEMP\TEMP1';
if CreateProcess(nil, PChar(AppParams), nil, nil, True, NORMAL_PRIORITY_CLASS, nil, PChar(AppPath), SI, P2) then begin
//I need to suppend the recv/send to the first process while this is running
Result2 := WaitForSingleObject(P2.hThread, 100);
until (Terminated) or (Result2 <> WAIT_TIMEOUT);
if Terminated then TerminateProcess(P2.hProcess, 0);
until (Terminated) or (Result1 <> WAIT_TIMEOUT);
if Terminated then TerminateProcess(PI.hProcess, 0);