Hello Ronaldo, At first sight I see nothing wrong with your code. However it is not normal that some of the sockets close without reason. Wich of the sockets do the close? Maybe the close is with a winsock error, then it will tell you more about the reason. You have at least log all the winsock errors in the different events.
Eventually you can also take a look at HpHttpProxy and SocketSpy, both available at user made page of overbyte.be wich does more or less the same as your application. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Thursday, April 30, 2009, 21:40, Ronaldo DeVinche wrote: > Hello! > i have made a proxy (sniffer) based on TWsockets from www.overbyte.be > all works perfect... i capture packet and if need before send it back i > modify it > the problem is that proxy disconnect in +/- 1 minute > is there is way how to increase or even disable thous disconnect timup`s or > whatever it calls > here is code > ########################## > type > TForm3 = class(TForm) > Socket: TWSocket; > Server: TWSocketServer; > Button1: TButton; > CheckBox1: TCheckBox; > Memo1: TMemo; > Edit1: TEdit; > Edit2: TEdit; > Edit3: TEdit; > Edit4: TEdit; > Label1: TLabel; > Label2: TLabel; > Memo2: TMemo; > Memo3: TMemo; > Button2: TButton; > procedure Button1Click(Sender: TObject); > procedure FormCreate(Sender: TObject); > procedure FormDestroy(Sender: TObject); > procedure ServerClientConnect(Sender: TObject; Client: TWSocketClient; > Error: Word); > procedure ServerClientDisconnect(Sender: TObject; Client: TWSocketClient; > Error: Word); > procedure ServerDataAvailable(Sender: TObject; ErrCode: Word); > procedure ServerError(Sender: TObject); > procedure SocketDataAvailable(Sender: TObject; ErrCode: Word); > procedure SocketSessionClosed(Sender: TObject; ErrCode: Word); > procedure SocketSessionConnected(Sender: TObject; ErrCode: Word); > procedure SocketSocksError(Sender: TObject; Error: Integer; Msg: string); > procedure Button2Click(Sender: TObject); > private > ClientConnected: Boolean; > ServerConnected: Boolean; > TestLoop:Boolean; > TestLoop2:Boolean; > TestLoop3:Boolean; > TestLoop4:Boolean; > { Private declarations } > public > LocalClient: TWSocketClient; > recvbuf, sendbuf: TWSocketData; > { Public declarations } > end; > var > Form3: TForm3; > implementation > {$R *.dfm} > procedure TForm3.Button1Click(Sender: TObject); > begin > if Button1.Caption = 'Stop Proxy' then > begin > Server.Close; > Socket.Close; > Button1.Caption:='Start Proxy'; > end > else > if Button1.Caption = 'Start Proxy' then > begin > server.Addr:=Edit1.Text; > server.port:=Edit2.Text; > server.Listen; > socket.addr:=Edit3.Text; > socket.port:=Edit4.Text; > Button1.Caption:='Stop Proxy'; > End; > End; > procedure TForm3.FormCreate(Sender: TObject); > begin > recvbuf:= AllocMem($FFFF); > sendbuf:= AllocMem($FFFF); > ClientConnected:= False; > end; > procedure TForm3.FormDestroy(Sender: TObject); > begin > FreeMem(recvbuf, $FFFF); > FreeMem(sendbuf, $FFFF); > socket.close; > server.close; > end; > procedure TForm3.ServerClientConnect(Sender: TObject; Client: > TWSocketClient; > Error: Word); > begin > LocalClient:= Client; > LocalClient.OnDataAvailable:= Server.onDataAvailable; > if checkbox1.checked then > Socket.Connect; > memo1.lines.add('Client connected!'); > ServerConnected:= True; > end; > procedure TForm3.ServerClientDisconnect(Sender: TObject; Client: > TWSocketClient; > Error: Word); > begin > memo1.lines.add('Client disconnected!'); > ServerConnected:= False; > if ClientConnected then > socket.close; > end; > procedure TForm3.ServerDataAvailable(Sender: TObject; ErrCode: Word); > var > Len: Integer; > begin > Len:= LocalClient.Receive(sendbuf, $FFFF); > memo2.lines.add( Format('Read from client %d bytes', [Len]) ); > if ClientConnected and (len>0) then > Socket.send(sendbuf, Len); > end; > procedure TForm3.ServerError(Sender: TObject); > begin > memo1.lines.add( Format('Error %d on server socket', [GetLastError]) ); > end; > procedure TForm3.SocketDataAvailable(Sender: TObject; ErrCode: Word); > var > Len: Integer; > begin > Socket.FlushTimeout:=0; > Len:= Socket.Receive(recvbuf, $FFFF); > memo3.lines.add( Format('Proxy Read from server %d bytes', [Len]) ); if (len>>0) then > LocalClient.send(recvbuf, Len); > end; > procedure TForm3.SocketSessionClosed(Sender: TObject; ErrCode: Word); > begin > memo1.lines.add('Proxy Disconnected from Server!'); > ClientConnected:= False; > end; > procedure TForm3.SocketSessionConnected(Sender: TObject; ErrCode: Word); > begin > ClientConnected:= True; > memo1.lines.add('Proxy connected to Server'); > end; > procedure TForm3.SocketSocksError(Sender: TObject; Error: Integer; Msg: > string); > begin > memo1.lines.add('aaaaaaaa'); > end; > end. > ########################## > Thank you! > Ronaldo -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be