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

Reply via email to