有关socket编程,我的程序为什么被告知"error connect to 10061?"?

dida200 2003-09-07 06:49:34
unit Unitmain;

interface

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

type
TForm1 = class(TForm)
ClientSocket: TClientSocket;
ServerSocket: TServerSocket;
connectButton: TButton;
disconnectButton: TButton;
listenButton: TButton;
Memo1: TMemo;
Memo2: TMemo;
StatusBar1: TStatusBar;
procedure listenButtonClick(Sender: TObject);
procedure connectButtonClick(Sender: TObject);
procedure disconnectButtonClick(Sender: TObject);
procedure ServerSocketAccept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure Memo1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
IsServer: Boolean;
Server,ConnectPort,ListenPort: String;

public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.connectButtonClick(Sender: TObject);

begin
if Clientsocket.Active then
begin
clientsocket.Active :=false;
statusbar1.Panels[0].Text := '';
end;
Server := '127.0.0.1';
ConnectPort := '54039';
if Length(server) > 0 then
{ with clientsocket do}
begin
clientsocket.Host:=Server;
clientsocket.Port := StrToInt(ConnectPort);
Clientsocket.Active :=True;
end
{ begin
Host := Server;
Port := StrToInt(ConnectPort);
Active := True;
end; }
end;

procedure TForm1.disconnectButtonClick(Sender: TObject);
begin
clientsocket.Active:=true;
Statusbar1.Panels[0].Text:='';
end;

procedure TForm1.ServerSocketAccept(Sender: TObject;
Socket: TCustomWinSocket);

begin
IsServer := True;
Statusbar1.Panels[0].Text:='Accept connection form:' + Socket.RemoteAddress;
end;
procedure TForm1.ServerSocketClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ShowMessage(IntToStr(ErrorCode));
end;
procedure TForm1.ClientSocketError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
memo2.Lines.Add('Error connecting to:'+IntToStr(ErrorCode));
ErrorCode :=0;
end;

end.
...全文
56 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
tiexinliu 2003-09-07
10061表示客户端与服务器连接失败,我的曾经出现这个问题,把子网掩码放宽以后解决,不知为什么,你试试看。
回复
CunningBoy 2003-09-07
你用的地址是127。0。0。1,即本地机,那么你的本地机应该打开服务器,使其处于监听状态,你的程序中使用的Serversocket,但我没有看到你把Serversocket的Active属性设为True,即没有使Serversocket处于活动状态,因此程序会提示,连接被拒绝。
回复
rwdx 2003-09-07
10061:
连接被拒。由于被目标机器拒绝,连接无法建立。这通常是由于在远程机器上,没有任何应用程序在那个地址上为连接提供服务
回复
相关推荐
发帖
网络通信/分布式开发
创建于2007-08-02

1573

社区成员

Delphi 网络通信/分布式开发
申请成为版主
帖子事件
创建了帖子
2003-09-07 06:49
社区公告
暂无公告