btnStartServer.OnClick(Sender:TObject); begin ss.Port:=2000; ss.Open; end;
ss.OnClientRead(Sender: TObject;Socket: TCustomWinSocket); var sTemp:string; bufRecv:Pointer; iRecvLength:integer; begin if bReadText then begin sTemp:=Socket.ReceiveText; case sTemp[1] of MP_QUERY:begin //在这里拒绝 SaveDialog1.FileName:=Copy(sTemp,2,Length(STemp)); if SaveDialog1.Execute then begin Socket.SendText(MP_ACCEPT); fsRecv:=TFileStream.Create(SaveDialog1.FileName,fmCreate); end else Socket.SendText(MP_REFUSE+'去死'); end; MP_FILEPROPERTY:begin //要发送StrToInt(Copy(sTemp,2,Length(sTemp))) 次 //时间进度显示。。。 Socket.SendText(MP_NEXTWILLBEDATA); end; MP_NEXTWILLBEDATA:begin Socket.SendText(MP_DATA); bReadText:=false; end; MP_END:begin fsRecv.Free bReadText:=true; end; MP_ABORT:begin fsRecv.Free; bReadText:=true; end; MP_CHAT:begin //Chat Msg end; end;{of case} end else begin try GetMem(bufRecv,2000);//2000 must >iBYTESEND Socket.ReceiveBuf(bufRecv^,iRecvLength); fsRecv.WriteBuffer(bufRecv^,iRecvLength); finally FreeMem(bufRecv,2000); end;{of try} bReadText:=true; Socket.SendText(MP_NEXTWILLBEDATA); end; end;