大家一定帮忙呀,一定,关于客户与主机连接(200分)

  • 主题发起人 主题发起人 X-ary
  • 开始时间 开始时间
X

X-ary

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个区域网的chat,当一连接就要进行拨号连接,稍后显示错误
" windows socket error: (11004),on API'ASync Lookup "
请问解决and避免拨号连接
顺便问一下,端口能随便填吗?
如不能改如何填。
请大家务必帮忙呀,谢谢
源码如下

服务器
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, inifiles,ToolWin, StdCtrls, Buttons, ScktComp, ImgList, ExtCtrls;

type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Memo1: TMemo;
TreeView1: TTreeView;
Edit1: TEdit;
ClientSocket1: TClientSocket;
ServerSocket1: TServerSocket;
ImageList1: TImageList;
RadioGroup1: TRadioGroup;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
RadioGroup2: TRadioGroup;
Edit4: TEdit;
StaticText1: TStaticText;
RadioGroup3: TRadioGroup;
Edit2: TEdit;
Edit3: TEdit;
StaticText2: TStaticText;
StaticText3: TStaticText;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
StaticText4: TStaticText;
StaticText5: TStaticText;
StatusBar1: TStatusBar;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
procedure ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
history: tinifile;
Form1: TForm1;
yourname,myname,receive,a,b,c: string;
implementation

{$R *.DFM}

procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
begin
treeview1.Items.addchild(treeview1.Selected,'talker');
treeview1.FullExpand;
memo1.Lines.add('大家注意!有朋友加入啦'+' '+timetostr(time));
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
treeview1.items.delete(treeview1.items.item[1]);
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
receive:=socket.ReceiveText;
memo1.Lines.add(receive);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
serversocket1.port:=strtoint(edit2.text);
history:=tinifile.create('c:/talking.ini');
a:=history.readstring('sound','sound','');
b:=history.readstring('windows','windows','');
c:=history.readstring('super','super','');
edit2.text:=history.readstring('DUAN','DUAN','');
edit3.text:=history.readstring('IP','IP','');
edit4.text:=history.readstring('name','name','');
if strtoint(a)=1 then
checkbox1.Checked:=true
else
checkbox1.checked:=false;
if strtoint(b)=1 then
checkbox2.Checked:=true
else
checkbox2.checked:=false;
if strtoint(c)=1 then
checkbox3.Checked:=true
else
checkbox3.checked:=false;
myname:=history.readstring('name','name','');
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if(key=vk_return) then
begin
if edit1.text<>'' then
begin
memo1.lines.add(myname+' 说:"'+edit1.text+'" '+timetostr(time));
edit1.clear;
end
else
showmessage('Oh,发空消息不好');
end

end;

procedure TForm1.BitBtn6Click(Sender: TObject);
begin
if edit4.text<>'' then
history.writestring('name','name',edit4.text)
else
showmessage('起个好听的名字吧');
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
begin
if (edit2.text<>'') and (edit3.text<>'') then
begin
history.WriteString('DUAN','DUAN',edit2.text);
history.WriteString('IP','IP',edit3.text);
end
else
showmessage('两个都应填写呀');

end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
if checkbox1.checked then
history.WriteString('sound','sound','1')
else
history.WriteString('sound','sound','0');
if checkbox2.checked then
history.WriteString('windows','windows','1')
else
history.WriteString('windows','windows','0');
if checkbox3.checked then
history.WriteString('super','super','1')
else
history.WriteString('super','super','0');
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
serversocket1.port:=strtoint(edit2.text);
serversocket1.Open;
statusbar1.Simpletext:='正在监听中......';
toolbutton1.Enabled:=false;
toolbutton2.enabled:=true;
end;

procedure TForm1.ToolButton2Click(Sender: TObject);
begin
toolbutton1.enabled:=true;
toolbutton2.enabled:=false;
serversocket1.Socket.close;
statusbar1.simpletext:='停止';
end;

end.
客户
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, inifiles,ToolWin, StdCtrls, Buttons, ScktComp, ImgList, ExtCtrls;

type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Memo1: TMemo;
TreeView1: TTreeView;
Edit1: TEdit;
ClientSocket1: TClientSocket;
ServerSocket1: TServerSocket;
ImageList1: TImageList;
RadioGroup1: TRadioGroup;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
RadioGroup2: TRadioGroup;
Edit4: TEdit;
StaticText1: TStaticText;
RadioGroup3: TRadioGroup;
Edit2: TEdit;
Edit3: TEdit;
StaticText2: TStaticText;
StaticText3: TStaticText;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
StatusBar1: TStatusBar;
procedure ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure ToolButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
history: tinifile;
Form1: TForm1;
yourname,myname,receive,a,b,c: string;
implementation

{$R *.DFM}

procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
begin
treeview1.Items.addchild(treeview1.Selected,'talker');
treeview1.FullExpand;
memo1.Lines.add('大家注意!有朋友加入啦'+' '+timetostr(time));
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
treeview1.items.delete(treeview1.items.item[1]);
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
receive:=socket.ReceiveText;
memo1.Lines.add(receive);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
serversocket1.port:=strtoint(edit2.text);
history:=tinifile.create('c:/talking.ini');
a:=history.readstring('sound','sound','');
b:=history.readstring('windows','windows','');
c:=history.readstring('super','super','');
edit2.text:=history.readstring('DUAN','DUAN','');
edit3.text:=history.readstring('IP','IP','');
edit4.text:=history.readstring('name','name','');
if strtoint(a)=1 then
checkbox1.Checked:=true
else
checkbox1.checked:=false;
if strtoint(b)=1 then
checkbox2.Checked:=true
else
checkbox2.checked:=false;
if strtoint(c)=1 then
checkbox3.Checked:=true
else
checkbox3.checked:=false;
myname:=history.readstring('name','name','');
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if(key=vk_return) then
begin
if edit1.text<>'' then
begin
memo1.lines.add(myname+' 说:"'+edit1.text+'" '+timetostr(time));
edit1.clear;
clientsocket1.socket.sendtext(edit1.text+timetostr(time));
end
else
showmessage('Oh,发空消息不好');
end

end;

procedure TForm1.BitBtn6Click(Sender: TObject);
begin
if edit4.text<>'' then
history.writestring('name','name',edit4.text)
else
showmessage('起个好听的名字吧');
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
begin
if (edit2.text<>'') and (edit3.text<>'') then
begin
history.WriteString('DUAN','DUAN',edit2.text);
history.WriteString('IP','IP',edit3.text);
end
else
showmessage('两个都应填写呀');

end;

procedure TForm1.BitBtn5Click(Sender: TObject);
begin
if checkbox1.checked then
history.WriteString('sound','sound','1')
else
history.WriteString('sound','sound','0');
if checkbox2.checked then
history.WriteString('windows','windows','1')
else
history.WriteString('windows','windows','0');
if checkbox3.checked then
history.WriteString('super','super','1')
else
history.WriteString('super','super','0');
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
clientsocket1.host:=edit3.text;
clientsocket1.port:=strtoint(edit2.text);
clientsocket1.open;
statusbar1.Simpletext:=('正在连接......');
toolbutton1.enabled:=false;
toolbutton2.enabled:=true;
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.simpletext:=('连接成功......');
end;

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.lines.add(clientsocket1.socket.receivetext);
end;

procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
statusbar1.simpletext:='连接失败......';
toolbutton1.enabled:=true;
end;

procedure TForm1.ToolButton2Click(Sender: TObject);
begin
toolbutton1.Enabled:=true;
toolbutton2.enabled:=false;
statusbar1.simpletext:='停止......';
clientsocket1.Close;
end;

end.

谢谢


 
你是不是没有网卡啊?否则不会出现拨号提示的,或者你可以把拨号网络适配器删掉试一试。
11004错误号是在dns域名解析中使用的,说明主机本身是存在的,但是不能直接到达。
 
哦,我试一试
 
将问题提前
 
同样的问题,同一个人,因此就同一个答案吧! :-)

答案见:
http://www.delphibbs.com/delphibbs/DispQ.asp?LID=321240
 
试一试internet选项中“连接”的“从不进行拨号连接”
 
接受答案了.
 

Similar threads

后退
顶部