我初始化tclientsocket为,这个tclientsocket是个全局变量;
try
Clientsocket:=TClientsocket.Create(self);
clientsocket.ClientType:=ctnonblocking;
clientsocket.Address:=‘127.0.0.1’;
clientsocket.Port:=3000;
while not clientsocket.Active do
begin
if clientsocket.Active then break;
clientsocket.Open;
application.ProcessMessages;
end;
if not clientsocket.Active then
begin
memo1.Lines.Add('socket打开失败');
exit;
end;
except
on e:exception do
begin
memo1.Lines.Add(e.Message);
exit;
end;
end;
if clientsocket.Active then memo1.Lines.Add('socket连接建立成功');
已经提示建立socket连接成功了;并且
但是在发送数据的时候又提示:
Windows socket error: 由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。 (10057), on API 'send'
try
Clientsocket:=TClientsocket.Create(self);
clientsocket.ClientType:=ctnonblocking;
clientsocket.Address:=‘127.0.0.1’;
clientsocket.Port:=3000;
while not clientsocket.Active do
begin
if clientsocket.Active then break;
clientsocket.Open;
application.ProcessMessages;
end;
if not clientsocket.Active then
begin
memo1.Lines.Add('socket打开失败');
exit;
end;
except
on e:exception do
begin
memo1.Lines.Add(e.Message);
exit;
end;
end;
if clientsocket.Active then memo1.Lines.Add('socket连接建立成功');
已经提示建立socket连接成功了;并且
但是在发送数据的时候又提示:
Windows socket error: 由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。 (10057), on API 'send'
127.0.0.1 就雖然是本機的, 但在win2k下, 如果你網卡沒聯到網絡,
可能也有問題!!還有, 有沒有ServerSocket對應聯接??
(包括拔掉网线)
说明楼主的贴出来的代码没问题,查查你别的代码unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
ClientSocket: TClientSocket;implementation{$R *.dfm}//打开Socket
procedure TForm1.Button1Click(Sender: TObject);
begin
try
Clientsocket:=TClientsocket.Create(self);
clientsocket.ClientType:=ctnonblocking;
clientsocket.Address:='127.0.0.1';
clientsocket.Port:=3000;
while not clientsocket.Active do
begin
if clientsocket.Active then break;
clientsocket.Open;
application.ProcessMessages;
end;
if not clientsocket.Active then
begin
memo1.Lines.Add('socket打开失败');
exit;
end;
except
on e:exception do
begin
memo1.Lines.Add(e.Message);
exit;
end;
end;
if clientsocket.Active then memo1.Lines.Add('socket连接建立成功');
end;//发送数据
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientSocket.Socket.SendText('AAAAAA');
end;end.
如果需要可自己安装:
http://www.588188.com/netbook/tech/delphi/html/delphi.ohchina.180.htm
成功之后就会在Internet页上就会有了。