遇到极怪问题,请求各位帮助(100分)

  • 主题发起人 主题发起人 liu_xj
  • 开始时间 开始时间
L

liu_xj

Unregistered / Unconfirmed
GUEST, unregistred user!
我编写一个远程屏幕拷贝程序,采用UDP协议和TMNUDP,一个客户端一个服务器端,服务器端获取客户端
屏幕指令后,客户端响应并将屏幕发送到服务器端,但在服务器接受时总出现错误。程序执行
读缓冲数据后就自动跳转发送缓冲代码。现将服务器原码如下:
unit Unit1;

interface

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

type
Tserver = class(TForm)
SUDP: TNMUDP;
Image1: TImage;
Label1: TLabel;
Button1: TButton;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure SUDPDataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
//procedure SUDPDataReceived(Sender: TComponent; NumberBytes: Integer; FromIP: String);
private
{ Private declarations }
public
{ Public declarations }
end;

var
server: Tserver;

implementation

{$R *.DFM}

const BufSize=2048;
var
RsltStream,TmpStream:TMemoryStream;

procedure TServer.FormCreate(Sender: TObject);
begin
RsltStream:=TMemoryStream.Create;
TmpStream:=TMemoryStream.Create;
end;

procedure TServer.FormDestroy(Sender: TObject);
begin
RsltStream.Free;
TmpStream.Free;
end;

procedure TServer.Button1Click(Sender: TObject);
var ReqCode:array[0..29] of char;ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.Text;
StrpCopy(ReqCode,ReqCodeStr);
//TmpStream.Clear;
//RsltStream.Clear;
label3.caption:=string(ReqCode);
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;


procedure Tserver.SUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var ReqCode:array[0..29] of char;ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.text;
StrpCopy(ReqCode,ReqCodeStr);
SUDP.ReadStream(TmpStream);// 问题所在处:执行改行后自动跳转发送数据处++++++++++=
RsltStream.CopyFrom(TmpStream,NumberBytes);
if NumberBytes< BufSize then { 数据已读完 }
begin
RsltStream.Position:=0;
Image1.Picture.Bitmap.LoadFromStream(RsltStream);
TmpStream.Clear;
RsltStream.Clear;
end
else begin
TmpStream.Clear;
ReqCode:='show';
SUDP.RemoteHost:=Edit2.Text;
sudp.readbuffer( ReqCode,NumberBytes);

SUDP.SendBuffer(ReqCode,30);//发送数据+++++++++++++++++++++++++
end;

end;
end.


 
SUDP.sendStream在何处?
 
就是拷贝的例程嘛,应该没问题的
 
后退
顶部