请教各们位不求名利的高手。怎么用NMUDP发送流?(20分)

  • 主题发起人 主题发起人 flycity
  • 开始时间 开始时间
F

flycity

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(]怎么用NMUDP发送流?
我用NMUDP1.sendstream(stream);//stream:tmemorystream;
用NMUDP1.readstream(stream);老是出错,我看了hubdog中的作法是stream.read(buf,n)
再用nmudp1.sendbuffer(buf,n);发送,为什么不能直接用流传输,而要转一下呢。
 
我没用过NMUDP,不过你可以把你实现发送的那段代码贴出来,否则看不出问题。
 
begin
dest:=tcanvas.Create;
bitmap:=tbitmap.create;
dest.Handle:=getdc(hwnd_desktop);
with bitmap do
begin
height:=screen.Height;
width:=screen.Width;
canvas.CopyRect(canvas.ClipRect,dest,dest.ClipRect);
end;
showmessage('发送信息...');
mystream:=tmemorystream.create;
jpeg:=tjpegimage.create;
jpeg.Assign(bitmap);
jpeg.CompressionQuality:=60;
jpeg.Compress;
jpeg.SaveToStream(mystream);
nmudp1.RemoteHost:='WU';
nmudp1.SendSTREAM(mystream);
 
参考一下这个:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=0601672
 
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
buf:array[1..2048] of char;
stream:tmemorystream;
bit:tbitmap;
begin
nmudp1.ReadBuffer(buf,numberbytes);
stream:=tmemorystream.Create;
stream.write(buf,numberbytes);
bit:=tbitmap.Create;
bit.LoadFromStream(stream);
form1.Canvas.Draw(0,0,bit);
stream.Free;
bit.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
bit:tbitmap;
stream:tmemorystream;
a:array[1..2048] of char;
begin
bit:=tbitmap.Create;
bit.LoadFromFile('d:/temp/w.bmp');
bit.SaveToStream(stream);
stream.Position:=0;
stream.read(a,stream.Size);
nmudp1.SendBuffer(a,stream.Size);
stream.Free;
bit.Free;
end;
[:D]to:zw84611,你给我的那段个贴子中说出错是因为stream大于2k,上段代码中的w.bmp只有1K多,发送时不出错,但接收时老是说"stream write error"这是为什么????
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部