做了个简单的三层测试程序,客户端用SocketConnection连接服务器。
服务器网络状况:局域网络内的一台机器连接到陆游器,陆游器有公网ip,并做了端口到主机的影射,21,25,80,5988四个端口可用,最后一个端口空闲,其它三个已经做了web,ftp,mail服务端口。开始的时候怎么也连不上。后面用了最后一个端口,提示出错“Invalid Data Packet”,不知道是什么原因??
找了很久资料还是没有解决,不知能否告知怎么通过SocketConnection连接远程服务器??
服务器网络状况:局域网络内的一台机器连接到陆游器,陆游器有公网ip,并做了端口到主机的影射,21,25,80,5988四个端口可用,最后一个端口空闲,其它三个已经做了web,ftp,mail服务端口。开始的时候怎么也连不上。后面用了最后一个端口,提示出错“Invalid Data Packet”,不知道是什么原因??
找了很久资料还是没有解决,不知能否告知怎么通过SocketConnection连接远程服务器??
var
remotehost : String;
begin
Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'LesterSoft.ini');
LFactoryName := Ini.ReadString('Factory','Name','');
//IniData := TIniFile.Create(ExtractFilePath(Application.ExeName) +LFactoryName+DateToStr(Now)+'.ini');
remotehost := Ini.ReadString('SERVER','IP','');
if trim(remotehost)<>''then
begin
if Cs.Active then
Cs.Active := True;
Cs.Port := 5000;
Cs.Host := remotehost;
try
Cs.Active := true;
except
showmessage('连接失败!');
end;
end;end;
-------------------procedure TForm1.SendBtnClick(Sender: TObject);
var
fs : TFileStream;
Buf : Pointer;
begin
fs := TFileStream.Create(edit1.Text,
fmOpenRead or fmShareDenyNone);
GetMem(Buf,fs.size);
fs.Seek(0,soFromBeginning);
fs.ReadBuffer(Buf^,fs.Size);
Richedit1.Lines.Add(DateToStr(Date)+
''+ TimeToStr(time)+
'==>>'+
'共发送 :'+
IntToStr(Cs.Socket.SendBuf(Buf^,fs.Size))+
'字节.');
self.Close;
end;server :
procedure TForm1.SSClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Df : PDataFlag;
cmd : String;
Buffer : Pointer;
nRetr : Integer;
fs : TFileStream;
s: TStringList;
const bufferSize = 1024;
begin
//showmessage('00000');
Df := Socket.Data;
case Df.WorkFlag of
0,3:
begin
cmd := trim(Socket.ReceiveText);
//showmessage(cmd+'');
s := TStringList.Create;
s.Add(cmd);
s.SaveToFile(label2.Caption+'NXOD'+dateToStr(Date)+'.ini');
....