关于用UDP协议发送图形文件的问题!(100分)

  • 主题发起人 主题发起人 sh6
  • 开始时间 开始时间
S

sh6

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用udp协议发送图形,但udp一次最好只能发送2k字节,请问
如何将图形拆分成n份连续发送?
 
行不行:
UDP协议,可基于INTERNET也可基于C/S,BO的原理你知道吗?他就是远程监控。
你定义一个枚举,写你要传达的命令,你在双方写一个大CASE,双方接到什么命令,判断命令,就做相应的事
例子:我从我的一个程序里复制的,如有不明白的地方给我写信.backmail@263.net

const
serverport=6666;
servercomputer='ljw';
clientport=7777;
MaxuserNum=101;
type
Tservercommand=(ackconnect,acksendmsg,ackdisconnect,ackonlineuser,ackrefresh);
Tclientcommand=(connect,sendmsg,disconnect);
Tuser=record
no:integer;
servercommand:Tservercommand;
clientcommand:Tclientcommand;
Ip:string[15];
nick:shortstring;
sex:string[4];
tonick:shortstring;
msg:shortstring;
face:shortstring;
color:tcolor;
time:shortstring;
Exonline:array[1..MaxuserNum]of string[4];
ExAck:boolean;
end;

procedure TForm1.udp1DataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
var
MyStream: TMemoryStream;
usermsg:tuser;
i,j:integer;
begin
MyStream := TMemoryStream.Create;
try
UDP1.ReadStream(MyStream);
MyStream.Read(usermsg,sizeof(usermsg));
case usermsg.clientcommand of
connect:
begin
j:=1;
for i:=1 to high(userarr) do
if userarr.no<>0 then
begin
onlinemsg[j].sex:=userarr.sex;
onlinemsg[j].nick:=userarr.nick;
j:=j+1;
end;
if onlinemsg[1].no<>0 then
begin
udp1.RemoteHost:=FromIp;
MyStream.Clear;
usermsg.servercommand:=ackonlineuser;
MyStream.Write(onlinemsg,sizeof(onlinemsg));
UDP1.SendStream(MyStream);
end;

for i:=1 to high(userarr) do
if userarr.no=0 then
begin
userarr.no:=i;
userarr.ip:=fromIp;
userarr.nick:=usermsg.nick;
break;
end;
udp1.RemoteHost:=FromIp;
MyStream.Clear;
usermsg.no:=userarr.no;
usermsg.servercommand:=ackconnect;
MyStream.Write(usermsg,sizeof(usermsg));
UDP1.SendStream(MyStream);

end;
disconnect:
begin
for i:=1 to high(userarr) do
if userarr.no=usermsg.no then
begin
userarr.no:=0;
break;
end;
MyStream.Clear;
udp1.RemoteHost:=fromip;
usermsg.servercommand:=ackdisconnect;
MyStream.Write(usermsg,sizeof(usermsg));
UDP1.SendStream(MyStream);
end;
sendmsg:
begin
usermsg.msg:='['+usermsg.nick+']'+usermsg.face+'对'+'['+usermsg.tonick+']'+'说>>'+string(usermsg.msg)+'('+usermsg.time+')';
usermsg.servercommand:=acksendmsg;
if usermsg.tonick='全部' then
begin
for i:=1 to high(userarr) do
begin
if trim(userarr.Ip)<>'' then
begin
udp1.RemoteHost:=trim(userarr.Ip);
mystream.Clear;
MyStream.Write(usermsg,sizeof(usermsg));
UDP1.SendStream(MyStream);
end;
end
end
else
begin
udp1.remotehost:=fromip;
mystream.Clear;
MyStream.Write(usermsg,sizeof(usermsg));
UDP1.SendStream(MyStream);
for i:=1 to high(userarr) do
if userarr.nick=usermsg.tonick then
begin
udp1.RemoteHost:=trim(userarr.Ip);
mystream.Clear;
MyStream.Write(usermsg,sizeof(usermsg));
UDP1.SendStream(MyStream);
break;
end;
end;
end;
end;
finally
freeandnil(MyStream);
end;
end;
 
接受答案了.
 
谢谢你,我正好想找这些资料,不好意思我借用一下了,有机会在一起讨论一下。
 

Similar threads

回复
0
查看
867
不得闲
回复
0
查看
1K
不得闲
D
回复
0
查看
928
DelphiTeacher的专栏
D
D
回复
0
查看
883
DelphiTeacher的专栏
D
D
回复
0
查看
856
DelphiTeacher的专栏
D
后退
顶部