delphi编程:用socket连接的问题

客户端:unitunit1;interfaceusesWindows,Messages,SysUtils,Classes,Graphics,Controls,Forms,... 客户端:

unit unit1;

interface

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

type
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Edit1: TEdit;
ClientSocket1: TClientSocket;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
c:longint;
m:tmemorystream;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
try
clientsocket1.Close;
clientsocket1.Host:=edit1.text;
clientsocket1.Open; //连接服务端
except
showmessage(edit1.text+#13#10+'未开机或未安装服务程序');
end;
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
showmessage(edit1.text+'通讯成功!');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if button2.enabled then
begin
clientsocket1.Socket.SendText('gets');
end;
end;

procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
caption:='连接'+edit1.text+'失败';
showmessage(edit1.text+#13#10+'未开机或未安装服务程序');
errorcode:=0;
end;

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
buffer:array [0..10000] of byte;
len:integer;
ll:string;
b:tbitmap;
j:tjpegimage;
begin
if c=0 then
begin
ll:=socket.ReceiveText;
c:=strtoint(ll);
clientsocket1.Socket.SendText('okok');
end else
begin
len:=socket.ReceiveLength;
socket.ReceiveBuf(buffer,len);
m.Write(buffer,len);
if m.Size>=c then
begin
m.Position:=0;
b:=tbitmap.Create;
j:=tjpegimage.Create;
try
j.LoadFromStream(m);
b.Assign(j); //将JPG转为BMP
Image1.Picture.Bitmap.Assign(b);
finally
b.free;
j.free;
clientsocket1.Active:=false;
clientsocket1.Active:=true;
m.Clear;
c:=0;
end;
end;
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
m:=tmemorystream.Create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
m.free;
ClientSocket1.Close;
end;

end.

为什么点击“连接”按钮之后,没有出现“通讯成功”的提示框?哪里出了问题??谢谢!
连接已经弄好了。。但是截图不成功。。。为什么?
展开
 我来答
若以下回答无法解决问题,邀请你更新回答
jyyyjy
2012-02-21 · 超过17用户采纳过TA的回答
知道答主
回答量:96
采纳率:0%
帮助的人:50.4万
展开全部
端口呢
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式