onconnect/onaccept事件没有发生?!ctNonBlocking或者ctBlocking都试过了,大家看看错在哪里啊?谢谢(100分)

  • 主题发起人 主题发起人 愚庶淋疯
  • 开始时间 开始时间

愚庶淋疯

Unregistered / Unconfirmed
GUEST, unregistred user!
Server端:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
ServerSocket1: TServerSocket;
procedure ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1Listen(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
var
a:string;
begin
showmessage('accept');
end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
var
a:string ;
begin
showmessage('connect');
end;

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

begin

showmessage('listen');
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
showmessage('read');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
form1.ServerSocket1.Port:=9494;
form1.ServerSocket1.Active:=true;
end;

end.

client端:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
ClientSocket1: TClientSocket;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Lookup(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
form1.ClientSocket1.Port:=9494;
form1.ClientSocket1.Host:='192.168.2.31';
form1.ClientSocket1.Active:=true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
form1.ClientSocket1.Socket.SendText('aaaa');
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
showmessage('onconnect');
end;

procedure TForm1.ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
begin
showmessage('onconnecting');
end;

procedure TForm1.ClientSocket1Lookup(Sender: TObject;
Socket: TCustomWinSocket);
begin
showmessage('onlookup');
end;

end.
 
ClientSocket不要用Host,改用Address。(ctNonBlocking)
 
请问!假设:Tserversocket中的Socket.Connections连接数为6,那么Socket.Connections[3]释放的话,其后的4、5、6是否会减1还是,Socket.Connections[3]空闲?
 
当然是都减1了,Connections是个列表,要用索引(从0开始)来访问
 
你不会用的是UDP协议吧?如果是,是不会发生connect和accept的.
 
接受答案了.
 
后退
顶部