请大家帮手看看以下网络数据传送的代码是否有错误!!!!!!!
以下代码运行总是导致网络连接中断,请帮忙!
{
type
in_data=record
con_code:smallint;//操作码
con_id:integer;//发送目的id号
mess_len:integer;//消息长度
file_size:int64;//文件长度
name_size:smallint;//文件名的长度
filename:string;//文件名
mess:string;//消息体,文本格式
end;
//以上变量已经在正确定义,此处只是说明。
}
function send_data(data_send:in_data):boolean;
var
this_connect:connect;
stream:TMemoryStream;
fs:tfilestream;
begin
this_connect:=find_id(data_send.con_id);
if this_connect.thread_id>0 then
begin
stream:=TMemoryStream.Create;
stream.WriteBuffer(data_send.con_code,sizeof(data_send.con_code));
stream.WriteBuffer(data_send.con_id,sizeof(data_send.con_id));
data_send.mess_len:=length(data_send.mess);
stream.WriteBuffer(data_send.mess_len,sizeof(data_send.mess_len));
stream.WriteBuffer(data_send.mess[1],data_send.mess_len);
if fileexists(data_send.filename) then
begin
data_send.name_size:=length(data_send.filename);
fs:=tfilestream.Create(data_send.filename,fmopenread);
data_send.file_size:=fs.Size;
stream.WriteBuffer(data_send.file_size,sizeof(data_send.file_size));//发送文件大小
stream.WriteBuffer(data_send.name_size,sizeof(data_send.name_size));//发送文件名大小
stream.WriteBuffer(data_send.filename[1],data_send.name_size);//发送文件名
stream.WriteBuffer(fs,data_send.file_size);//发送文件体
fs.Free;
end
else
begin
data_send.file_size:=0;
stream.WriteBuffer(data_send.file_size,sizeof(data_send.file_size));//发送文件大小0
end;
this_connect.objects.Connection.WriteStream(stream,true,true);
stream.Free;
result:=true;
end
else
result:=false;
end;