有关代理服务器的一段代码,大家给看看毛病再哪儿,谢谢(50分)

  • 主题发起人 主题发起人 sun112233
  • 开始时间 开始时间
S

sun112233

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个代理服务器软件,以下代码想实现最简单的,只能通过代理上‘www.163.com’可总是不行,麻烦各位高手指点一一下,还有象这样简单的代理软件,应该怎样设置才能用呢?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp;

type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
ServerSocket1: TServerSocket;
procedure FormCreate(Sender: TObject);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocket1Write(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
sock:Tclientsocket;
tmp:string;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
serversocket1.Port:=1024;
serversocket1.Active:=true;
end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
sock:=Tclientsocket.Create(nil);
sock.OnRead:=clientsocket1read;
sock.OnWrite:=clientsocket1write;
end;

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
buf:array[0..2047]of char;
rvsize:integer;
begin
rvsize:=socket.ReceiveBuf(buf,2048);
serversocket1.Socket.Connections[0].SendBuf(buf,rvsize);
end;

procedure TForm1.ClientSocket1Write(Sender: TObject;
Socket: TCustomWinSocket);
begin
socket.SendText(tmp);
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
tmp:=socket.ReceiveText;
sock.Host:='www.163.com';
sock.Port:=80;
sock.Open;
sock.Socket.SendText(tmp);
end;

end.
 

sock.Host:='www.163.com';
sock.Port:=80;
sock.Open; //异步模式下Open以后不一定就连接上了
//sock.Socket.SendText(tmp); //这段代码可以去掉

而且你收到数据就sock.open一次,这个地方有很多问题。如果第一次数据收不全,
那么请求就不完整。

 
服务器端和客户端应怎么设置才能用呢?
 
后退
顶部