I have found this article explainign how to inherit from a socket handle:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/shared_sockets_2.asp

--
[EMAIL PROTECTED]
http://www.overbyte.be

----- Original Message ----- 
From: "Francois Piette" <[EMAIL PROTECTED]>
To: "ICS support mailing" <twsocket@elists.org>
Sent: Tuesday, May 24, 2005 4:33 PM
Subject: Re: [twsocket] Telnet


> >   ShellExecute(Application.Handle, 'open', @ClientFileName,
@ClientParams,
> > @ClientDir, SW_SHOW);
>
> I'm not sure you can use ShellExecute to inherit handles. Use
CreateProcess which has a parameter
> bInheritHandles.
>
> > to server with "telnet 127.0.0.1 5000"... The client project is
executed,
> > but show message "10038".
>
> Error 10038 means you pass a handle to winsock that is not a socket
handle. In your case, the handle
> is not inherited from the parent process.
>
> --
> [EMAIL PROTECTED]
> http://www.overbyte.be
>
>
> ----- Original Message ----- 
> From: "Arnoldo - Optextil" <[EMAIL PROTECTED]>
> To: "ICS support mailing" <twsocket@elists.org>
> Sent: Tuesday, May 24, 2005 3:23 PM
> Subject: Re: [twsocket] Telnet
>
>
> > Hi,
> >
> > About redirect the connection, I created two small projects, exemplify
the
> > problem !
> >
> > Server:
> >
> > unit UServer;
> >
> > interface
> >
> > uses
> >   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
> >   Dialogs, WSocket, SHELLAPI;
> >
> > type
> >   TForm1 = class(TForm)
> >     SrvSocket: TWSocket;
> >     procedure FormCreate(Sender: TObject);
> >     procedure SrvSocketSessionAvailable(Sender: TObject; ErrCode: Word);
> >   private
> >     { Private declarations }
> >   public
> >     { Public declarations }
> >   end;
> >
> > var
> >   Form1: TForm1;
> >
> > implementation
> >
> > {$R *.dfm}
> >
> > procedure TForm1.FormCreate(Sender: TObject);
> > begin
> >   SrvSocket.Close;
> >   SrvSocket.Addr  := '0.0.0.0';  { Use any interface for listening }
> >   SrvSocket.Proto := 'tcp';
> >   SrvSocket.Port  := '5000';
> >   SrvSocket.Listen;
> > end;
> >
> > procedure TForm1.SrvSocketSessionAvailable(Sender: TObject; ErrCode:
Word);
> > var
> >   ClientFileName, ClientParams, ClientDir : array [0..255] of char;
> >   NewHSocket : TSocket;
> > begin
> >   NewHSocket := SrvSocket.Accept;
> >   StrPCopy(@ClientFileName, 'c:\rf\projectcliente.exe');
> >   StrPCopy(@ClientParams, ''+ inttostr(newhsocket));
> >   StrPCopy(@ClientDir, 'c:\rf\');
> >   ShellExecute(Application.Handle, 'open', @ClientFileName,
@ClientParams,
> > @ClientDir, SW_SHOW);
> > end;
> >
> > Client:
> >
> > unit UCliente;
> >
> > interface
> >
> > uses
> >   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
> >   Dialogs, WSocket, Spin, StdCtrls, Buttons, WinSock;
> >
> > type
> >   TForm2 = class(TForm)
> >     Socket: TWSocket;
> >     Memo: TMemo;
> >     procedure SocketDataAvailable(Sender: TObject; ErrCode: Word);
> >     procedure FormCreate(Sender: TObject);
> >   private
> >     { Private declarations }
> >   public
> >     { Public declarations }
> >   end;
> >
> > var
> >   Form2: TForm2;
> >
> > implementation
> >
> > {$R *.dfm}
> >
> > procedure TForm2.SocketDataAvailable(Sender: TObject; ErrCode: Word);
> > var
> >     Buffer : array [0..1023] of char;
> >     Len : Integer;
> > begin
> >   Len := Socket.Receive(@Buffer, SizeOf(Buffer) - 1);
> >   if Len <= 0 then
> >      Exit;
> >
> >   Buffer[Len]       := #0;
> >   Memo.lines.add(StrPas(Buffer));
> > end;
> >
> > procedure TForm2.FormCreate(Sender: TObject);
> > var
> >   NewHSocket : TSocket;
> > begin
> >   if  paramcount = 1 then
> >       Begin
> >         caption := ParamStr(1);
> >         NewHSocket := StrToIntDef(ParamStr(1),0);
> >         Socket.Dup(NewHSocket);
> >       End;
> > end;
> >
> > Running this example, the server is listen on port 5000, on prompt I
connect
> > to server with "telnet 127.0.0.1 5000"... The client project is
executed,
> > but
> > show message "10038".
> >
> > When you say: "Once you have the
> > socket handle for the accepted connection, you may start another
process,
> > make it inherit the handle and let him process the connection. The
second
> > process may use TWSocket and receive the inherited handle using Dup(). "
> >
> > The implementation above is correct ? If not, have a sample ?
> >
> > Thanks
> >
> > Arnoldo
> >
> > ----- Original Message ----- 
> > From: "Francois PIETTE" <[EMAIL PROTECTED]>
> > To: "ICS support mailing" <twsocket@elists.org>
> > Sent: Saturday, May 21, 2005 4:41 AM
> > Subject: Re: [twsocket] Telnet
> >
> >
> > >> I'm not reinventing the wheel. I saw your samples programs about
> > >> TWSocketServer too. My problem not is work with various instances of
> > >> clients. My problem is when the client connect the server, the server
> > >> redirect the connection to another application. I have the
Socket.Accept,
> > > I
> > >> run another application, in this another application who I do
establish
> > >> connection with the client ? It's possible ?
> > >
> > > Altough I have nerver done this, I think it is possible. Once you have
the
> > > socket handle for the accepted connection, you may start another
process,
> > > make it inherit the handle and let him process the connection. The
second
> > > process may use TWSocket and receive the inherited handle using Dup().
You
> > > have somewhat to split TWSocketServer in two parts. The listening part
> > > stay
> > > in one process and the client handling goes into another one.
> > >
> > > --
> > > [EMAIL PROTECTED]
> > > http://www.overbyte.be
> > >
> > >
> > > -- 
> > > To unsubscribe or change your settings for TWSocket mailing list
> > > please goto http://www.elists.org/mailman/listinfo/twsocket
> > > Visit our website at http://www.overbyte.be
> >
> >
> >
> > -- 
> > To unsubscribe or change your settings for TWSocket mailing list
> > please goto http://www.elists.org/mailman/listinfo/twsocket
> > Visit our website at http://www.overbyte.be
> >
>
>
> -- 
> To unsubscribe or change your settings for TWSocket mailing list
> please goto http://www.elists.org/mailman/listinfo/twsocket
> Visit our website at http://www.overbyte.be
>


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to