E
emailqjc
Unregistered / Unconfirmed
GUEST, unregistred user!
我们平时在开发分布式程序的时候都用TClientSocket,TServerSocket,为了技术保密,我想把我的一些重要的东西封装在dll中,封装好了,我在调用的时候能连接到服务端,怎么就不能发送出去数据呢(服务端和客户端都在同一台机器,服务端的端口:20000),代码如下:
//DLL代码:
library ProComIntfac;
uses
ShareMem,
SysUtils,
Classes,
Windows,
IdGlobal,
Registry,ScktComp;
var
CSocket:TClientSocket;
{$R *.res}
Function SendCMD(AHost:String;APort:Word;AStr:String):Word;Stdcall;
Begin
Result:=1;
CSocket:=TClientSocket.Create(nil);
CSocket.ClientType:=ctNonBlocking;
CSocket.Host:=AHost;
CSocket.Port:=APort;
try
CSocket.Active:=False;
CSocket.Active:=True;
CSocket.Socket.SendText(AStr);
except
Result:=0;
end;
End;
exports {ConnServer name 'ConnServer',}
SendCMD name 'SendCMD' ;
begin
end.
//服务端设置:
Host:127.0.0.1
Port:20000
//调用代码:
SendCMD('127.0.0.1,20000,'你好')
//DLL代码:
library ProComIntfac;
uses
ShareMem,
SysUtils,
Classes,
Windows,
IdGlobal,
Registry,ScktComp;
var
CSocket:TClientSocket;
{$R *.res}
Function SendCMD(AHost:String;APort:Word;AStr:String):Word;Stdcall;
Begin
Result:=1;
CSocket:=TClientSocket.Create(nil);
CSocket.ClientType:=ctNonBlocking;
CSocket.Host:=AHost;
CSocket.Port:=APort;
try
CSocket.Active:=False;
CSocket.Active:=True;
CSocket.Socket.SendText(AStr);
except
Result:=0;
end;
End;
exports {ConnServer name 'ConnServer',}
SendCMD name 'SendCMD' ;
begin
end.
//服务端设置:
Host:127.0.0.1
Port:20000
//调用代码:
SendCMD('127.0.0.1,20000,'你好')