技术文章 > 使用C++ Builder封装Tuxedo客户端调用

使用C++ Builder封装Tuxedo客户端调用

2018-07-17 23:08

文档管理软件,文档管理系统,知识管理系统,档案管理系统的技术资料:
本文主要介绍如何使用C++ Builder把Tuxedo客户端的调用封装成一个独立的类CTuxCall,最大程度的方便用户调用tuxedo,并给出相应的例子,以供参考.由于是第一次发表这样的文章,其中不足之处,还望大家予以批评指正。
类CTuxCall的特点
封装后的类CTuxCall有如下一些特点,能够最大程度的满足用户的需求,方便用户的调用.
(1) 可以自定义连接方式,长连接,短连接和混合连接(由用户自定义连接次数,当实际的连接次数超过自定义的连接次数,则自动断开连接,然后重连);
(2) 可以自动切换连接地址,目前提供了5个备用地址,只要其中有一个地址上的服务是正常的,则Tuxedo的连接就是正常的;
(3) 能够方便的设置客户端的信息,如操作员名称,操作员IP地址,或者操作员当前操作状态;
(4) 调用方式简单,灵活,可扩充性好.
类CTuxCall函数说明
(1) 设置客户端信息,在这里你可以设置操作员或者终端,甚至是一些操作状态的信息:
void SetClientInfo(char* username,char* ctlname);
使用该函数后,在服务器的管理平台,使用pclt命令,就会显示客户端的相关
信息,如:
LMID User Name Client Name Time Status Bgn/Cmmt/Abrt
--------------- --------------- --------------- -------- ------- -------------
szx1app tuxedo WSH 21:54:08 IDLE 0/0/0
szx1app oper01 192.168.1.114 0:18:15 IDLE/W 0/0/0
(2) 设置连接方式: bool SetConnectType(int contype);
(3) 设置监听地址: bool SetWSNAddr(char* addrlist);
参数格式如下:
"//ip1:port1;//ip2:port2;....;//ip5:port5" ,最多支持5个IP地址.
(4) 服务调用: Invoke();在客户端编写代码,只要调用这个函数即可.关于这个函数
有几个不同的函数原形,具体如下:
bool Invoke(char * OpCode,...);
指定操作码,调用确省服务,参数个数不定,至于如何把传入的参数一定的格式
写入到发送缓冲去,需要调用自定义的函数进行打包.
bool Invoke(char* SrvName,char* OpCode,...);
大体内容同上,只是调用的是指定的服务,而不是确省的服务.
bool Invoke(char* SrvName,long InLen,long &OutLen);
在使用此函数之前,必须保证先调用SetSendBuf()函数填充发送缓冲区.
bool Invoke(char * SrvName,char * InStr,long InLen, char * &OutStr, long &OutLen,int flag = 0);
调用指定服务,输入参数和返回结果都由用户自定.
(5) 填充发送缓冲区:int SetSendBuf(char *szFormat,...);
该函数用法同c语言的printf()函数,只是发送缓冲区的长度有限制,最好不要超过1024*10个字节.
源码分析
类CTuxCall的源码
TuxCall头文件
//---------------------------------------------------------------------------
#ifndef TuxCallH
#define TuxCallH
//---------------------------------------------------------------------------
#if defined(__BORLANDC__)&&!defined(SOCKET_CONNECT)
//#pragma comment (lib,"libtux.lib")
//#pragma comment (lib,"libbuft.lib")
//#pragma comment (lib,"libfml.lib")
//#pragma comment (lib,"libfml32.lib")
//#pragma comment (lib,"libengine.lib")
#endif
#define TRANSMITER "TRANSMIT"
class CTuxCall
{
private:
char * m_RecBuff;
char * m_SendBuff;
char ErrMsg[1024];
void ClearBuffer();
int m_Errno;
bool m_bBeginTrans;
int m_ConnectionType; //连接方式:0:长连接,1:短连接;m(m>10):m次调用后自动断开连接,并自动重连
int m_ConCount; //服务调用计数器
char m_UserName[64];
char m_CtrName[64];
char m_WSNAddrList[5][64];
char m_CurWSNADDR[64];
bool m_bInConnection; //是否正处在连接之中
bool CheckWSNADDRValid(char* ipstr,char* port);
char * GetErrMsg(char * ATitle,char * AMsg="");
bool AllocSrc(int size);
bool AllocDest(int size);
char m_EscapeFlag;
int m_Col; //返回结果每条记录的字段数
long m_Row; //返回结果的记录数
char m_ColSep[5]; // 字段间的分隔符
char m_RowSep[5]; // 记录间的分隔符
public:
CTuxCall();
~CTuxCall();
void SetClientInfo(char* username,char* ctlname);
bool SetConnectType(int contype);
bool SetWSNAddr(char* addrlist);
// addrlist="//ip1:port1;//ip2:port2;....;//ip5:port5" 最多支持5个IP地址.
void Disconnect();
bool Invoke(char * SrvName,char * InStr,long InLen, char * &OutStr, long &OutLen,int flag = 0);
bool Invoke(char * OpCode,...);
bool Invoke(char* SrvName,char* OpCode,...);
bool Invoke(char* SrvName,long InLen,long &OutLen);
bool BeginTransaction(unsigned long timeout=120);
bool Rollback();
bool Commit();
bool TuxInit();
bool TuxTerm();
char *GetErrorMessage();
char *GetCurWSNAddr();
char *GetResultData();
int SetSendBuf(char *szFormat,...); //总字符串的长度不超过1024*10个字节.
};
#endif
CTuxCall的实现
#pragma hdrstop
#include "TuxCall.h"
#ifndef _TM_WIN
#define _TM_WIN
#endif
#include "atmi.h"
#include "stdio.h"
#include
#include
#ifndef _NOAUTOLIB
#ifndef _NOAUTOMSG
#pragma message( "Will automatically link with libbuft.lib" )
#endif
#pragma comment(lib, "libbuft.lib")
#ifndef _NOAUTOMSG
#pragma message( "Will automatically link with libnwi.lib" )
#endif
#pragma comment(lib, "libnwi.lib")
#ifndef _NOAUTOMSG
#pragma message( "Will automatically link with libnws.lib" )
#endif
#pragma comment(lib, "libnws.lib")
#ifndef _NOAUTOMSG
#pragma message( "Will automatically link with libwsc.lib" )
#endif
#pragma comment(lib, "libwsc.lib")
#ifndef _NOAUTOMSG
#pragma message( "Will automatically link with libfml.lib" )
#endif
#pragma comment(lib, "libfml.lib")
#ifndef _NOAUTOMSG
#pragma message( "Will automatically link with libfml32.lib" )
#endif
#pragma comment(lib, "libfml32.lib")
#ifndef _NOAUTOMSG
#pragma message( "Will automatically link with libgp.lib" )
#endif
#pragma comment(lib, "libgp.lib")
#endif
//---------------------------------------------------------------------------
CTuxCall::CTuxCall()
{
m_bBeginTrans = false;
m_ConnectionType = 0;
m_ConCount = 0;
m_bInConnection = false;
memset(m_WSNAddrList,0,sizeof(m_WSNAddrList));
m_RecBuff=NULL;
m_SendBuff=NULL;
m_Row =0;
m_Col =0;
m_EscapeFlag = “\\“;
memset(m_ColSep,0,sizeof(m_ColSep));
strcpy(m_ColSep,"~#~");
memset(m_RowSep,0,sizeof(m_ColSep));
strcpy(m_RowSep,"`^`");
}
CTuxCall::~CTuxCall()
{
if(m_RecBuff)
tpfree(m_RecBuff);
if(m_SendBuff)
tpfree(m_SendBuff);
tpterm();
m_RecBuff = NULL;
m_SendBuff = NULL;
}
char * CTuxCall::GetErrMsg(char * ATitle,char * AMsg)
{
if(strlen(AMsg)!=0)
sprintf(ErrMsg,"%s\n错误代码:%d\n错误信息:%s",ATitle,m_Errno,AMsg);
else
sprintf(ErrMsg,"%s\n错误代码:%d\n错误信息:%s",ATitle,tperrno,tpstrerror(tperrno));
return ErrMsg;
}
bool CTuxCall::SetWSNAddr(char* addrlist)
{
//addrlist的格式: //IP1:PORT1;//IP2:PORT2;//IP3:PORT3;.....
char tmpAddr[64*5]={0};
char ipstr[32]={0};
char port[16]={0};
int nPos = 0;
int iPos = 0;
char *ptr=NULL;
memset(m_WSNAddrList,0,sizeof(m_WSNAddrList));
memset(tmpAddr,0,sizeof(tmpAddr));
strncpy(tmpAddr, addrlist,64*5);
int i=0;
while (i<5)
{
ptr = strstr(tmpAddr,";");
if (ptr)
{
nPos = ptr - tmpAddr;
memset(m_CurWSNADDR,0,sizeof(m_CurWSNADDR));
strncpy(m_CurWSNADDR,tmpAddr,nPos);
//strncpy(tmpAddr,ptr+1,strlen(ptr+1));
//tmpAddr[strlen(ptr+1)-nPos]=“\0“;
strcpy(tmpAddr,ptr+1);
ptr = strstr(m_CurWSNADDR,":");
if (ptr)
{
iPos = ptr - m_CurWSNADDR ;
memset(ipstr,0,sizeof(ipstr));
memset(port,0,sizeof(port));
if (m_CurWSNADDR[0]==“/“&&m_CurWSNADDR[1]==“/“)
{
strncpy(ipstr,m_CurWSNADDR+2,iPos-2);
strncpy(port,ptr+1,strlen(ptr+1));
}
else
{
strncpy(ipstr,m_CurWSNADDR,iPos);
strncpy(port,ptr+1,strlen(ptr+1));
}
if (CheckWSNADDRValid(ipstr,port))
{
strncpy(m_WSNAddrList[i],m_CurWSNADDR,strlen(m_CurWSNADDR));
i++;
}
else
{
m_Errno = -28;
GetErrMsg("参数设置错误","WSNADDR的IP地址或者监听端口无效.");
return false;
}
}
else
{
m_Errno = -28;
GetErrMsg("参数设置错误","WSNADDR的IP地址或者监听端口无效.");
return false;
}
}
else
{
//IP5:PORT5
ptr = strstr(tmpAddr,":");
if (ptr)
{
iPos = ptr-tmpAddr ;
memset(ipstr,0,sizeof(ipstr));
memset(port,0,sizeof(port));
if (tmpAddr[0]==“/“&&tmpAddr[1]==“/“)
{
strncpy(ipstr,tmpAddr+2,iPos-2);
strncpy(port,ptr+1,strlen(ptr+1));
}
else
{
strncpy(ipstr,tmpAddr,iPos);
strncpy(port,ptr+1,strlen(ptr+1));
}
if (CheckWSNADDRValid(ipstr,port))
{
strncpy(m_WSNAddrList[i],m_CurWSNADDR,strlen(m_CurWSNADDR));
break;
}
else
{
m_Errno = -28;
GetErrMsg("参数设置错误","WSNADDR的IP地址或者监听端口无效.");
return false;
}
}
else
{
m_Errno = -28;
GetErrMsg("参数设置错误","WSNADDR的IP地址或者监听端口无效.");
return false;
}
}
}
memset(m_CurWSNADDR,0,sizeof(m_CurWSNADDR));
strncpy(m_CurWSNADDR,m_WSNAddrList[0],64);
tuxputenv(m_CurWSNADDR);
return true;
}
bool CTuxCall::TuxInit()
{
if(m_bInConnection)
{
m_Errno = -9;
GetErrMsg("初始化Tuxedo错误","Tuxedo远程连接已经建立,不需要再次建立.");
return true;
}
TPINIT *tpinitbuf = (TPINIT*)tpalloc("TPINIT",NULL,sizeof(TPINIT));
strcpy(tpinitbuf->usrname,m_UserName);
strcpy(tpinitbuf->cltname,m_CtrName);
int i=1;
while (i<5)
{
if (tpinit(tpinitbuf) == -1)
{
m_Errno = tperrno;
GetErrMsg("初始化Tuxedo错误","无法建立tuxedo远程连接.");
memset(m_CurWSNADDR,0,sizeof(m_CurWSNADDR));
strncpy(m_CurWSNADDR,m_WSNAddrList[i],64);
tuxputenv(m_CurWSNADDR);
i++;
}
else
{
m_bInConnection = true;
break;
}
}
tpfree((char*)tpinitbuf);
return m_bInConnection;
}
bool CTuxCall::TuxTerm()
{
if( m_bInConnection && m_ConCount > m_ConnectionType)
{
tpterm();
m_ConCount =0;
}
else
{
return false;
}
m_bInConnection = false;
return true;
}
bool CTuxCall::AllocDest(int size)
{
m_RecBuff=tpalloc("CARRAY", NULL, size+1);
if(m_RecBuff==NULL){
m_Errno = tperrno;
GetErrMsg("分配内存出错","可能是申请的空间太大,没有足够的内存可以使用.");
return false;
}
return true;
}
bool CTuxCall::AllocSrc(int size)
{
m_SendBuff=tpalloc("CARRAY", NULL, size+1);
if(m_SendBuff==NULL){
m_Errno = tperrno;
GetErrMsg("分配内存出错","可能是申请的空间太大,系统内存不足!");
return false;
}
return true;
}
int CTuxCall::SetSendBuf(char *szFormat,...)
{
va_list ap;
char *arg=NULL;
int len = 0;
va_start(ap,szFormat);
char tmpStr[1024*10]={0};
vsprintf(tmpStr,szFormat, ap);
va_end(ap);
len = strlen(tmpStr);
if(m_SendBuff)
tpfree(m_SendBuff);
m_SendBuff=NULL;
if (!AllocSrc(len+1)) return -1;
memcpy(m_SendBuff,tmpStr,len);
return len;
}
//直接使用该服务之前,必须保证m_SendBuff中的内容是正确的,
//可以调用SetSendBuf()函数设置m_SendBuff的内容.
bool CTuxCall::Invoke(char* SrvName,long InLen,long &OutLen)
{
if(m_RecBuff)
tpfree(m_RecBuff);
m_RecBuff=NULL;
if (!AllocDest(1)) return false;
if (!TuxInit()) return false;
if(tpcall(SrvName,m_SendBuff,InLen,&m_RecBuff,&OutLen,0)==-1)
{
if(!m_bBeginTrans)
{
tpterm();
m_bInConnection = false;
}
char tmp[256];
sprintf(tmp,"调用服务 %s 出错",SrvName);
m_Errno = tperrno;
GetErrMsg("严重错误",tmp);
return false;
}
if (m_ConnectionType>0) m_ConCount++;
if(!m_bBeginTrans)
{
TuxTerm();
}
return true;
}
bool CTuxCall::Invoke(char * SrvName,char * InStr,long InLen, char * &OutStr,long &OutLen, int flag)
{
//首先清除Buffer,有效防止内存泄漏
ClearBuffer();
if (!AllocSrc(InLen)) return false;
memcpy(m_SendBuff,InStr,InLen);
if (!AllocDest(1)) return false;
if (!TuxInit()) return false;
if(tpcall(SrvName,m_SendBuff,InLen,&m_RecBuff,&OutLen,0)==-1)
{
if(!m_bBeginTrans)
{
tpterm();
m_bInConnection = false;
}
char tmp[256];
sprintf(tmp,"调用服务 %s 出错",SrvName);
m_Errno = tperrno;
GetErrMsg("严重错误",tmp);
return false;
}
if (m_ConnectionType>0) m_ConCount++;
if(!m_bBeginTrans)
{
TuxTerm();
}
OutStr=m_RecBuff;
return true;
}
/*
** 默认Invoke,默认服务名为TRANSMIT
*/
bool CTuxCall::Invoke(char * OpCode,...)
{
va_list ap;
va_start(ap, OpCode);
//序列化输入参数
va_end(ap);
long nOutLen;
char* pOutBuf;
int nInLen = 0;
char* pInBuf = NULL; //需要对输入的参数进行组合整理
bool ret;
try
{
ret = Invoke(TRANSMITER,pInBuf,nInLen,pOutBuf,nOutLen);
}catch(...)
{
delete []pInBuf;
return false;
}
delete []pInBuf;
return ret;
}
/*
** 指定服务名Invoke
*/
bool CTuxCall::Invoke(char* SrvName,char* OpCode,...)
{
va_list ap;
va_start(ap, OpCode);
//序列化输入参数
m_Col = 0;
/*
while ((arg =va_arg(ap,char*)) != 0)
{
//至于如何把传入的参数组合成一个二进制字符串,
//大家可以用自己的方法去处理,
//这里涉及的是其他方面的技术,跟tuxedo无关,所以不跟帖.
}
*/
va_end(ap);
long nOutLen;
char* pOutBuf;
int nInLen = 0;
char* pInBuf = NULL;
bool ret = false;
try
{
ret = Invoke(SrvName,pInBuf,nInLen,pOutBuf,nOutLen);
}catch(...)
{
delete []pInBuf;
return false;
}
delete []pInBuf;
return ret;
}
bool CTuxCall::BeginTransaction(unsigned long timeout)
{
TuxInit();
if(tpbegin(timeout,0)==-1)
{
tpterm();
m_bInConnection = false;
m_Errno = tperrno;
GetErrMsg("事务失败","无法开始事务");
return false;
}
m_bBeginTrans = true;
return true;
}
bool CTuxCall::Rollback()
{
if(!m_bBeginTrans)
{
m_Errno = -101;
GetErrMsg("事务失败","回滚之前应先开始一个事务!");
return false;
}
m_bBeginTrans = false;
if(tpabort(0)==-1)
{
tpterm();
m_bInConnection = false;
m_Errno = tperrno;
GetErrMsg("回滚事务失败","调用tpabort()函数失败!");
return false;
}
TuxTerm();
return true;
}
bool CTuxCall::Commit()
{
if(!m_bBeginTrans)
{
m_Errno = -102;
GetErrMsg("事务失败","提交之前应先开始一个事务!");
return false;
}
m_bBeginTrans = false;
if(tpcommit(0)==-1)
{
tpterm();
m_bInConnection = false;
m_Errno = tperrno;
GetErrMsg("提交事务失败","调用tpcommit()失败!");
return false;
}
TuxTerm();
return true;
}
void CTuxCall::Disconnect()
{
tpterm();
}
void CTuxCall::ClearBuffer()
{
if(m_RecBuff)
tpfree(m_RecBuff);
if(m_SendBuff)
tpfree(m_SendBuff);
m_RecBuff=NULL;
m_SendBuff=NULL;
}
void CTuxCall::SetClientInfo(char* username,char* ctlname)
{
strncpy(m_UserName,username,64);
m_UserName[63]=“\0“;
strncpy(m_CtrName,ctlname,64);
m_CtrName[63]=“\0“;
}
bool CTuxCall::SetConnectType(int contype)
{
if (contype==0||contype==1||contype>=10)
{
m_ConnectionType = contype;
return false;
}
else
{
m_Errno = -34;
GetErrMsg("参数设置错误","连接只能是0(长连接),1(短连接)和大于10的整数.");
return false;
}
}
bool CTuxCall::CheckWSNADDRValid(char* ipstr,char* port)
{
int iplen = strlen(ipstr);
if (iplen > 15) return false;
int count = 0;
char ipstrSubs[4]={0};
int iPos=0,i=0;
while (i {
if (ipstr[i]>=“0“&&ipstr[i]<=“9“)
{
if (iPos>3) return false;
ipstrSubs[iPos]=ipstr[i];
iPos++;
if (i==iplen-1)
{
ipstrSubs[iPos]=“\0“;
iPos = 0;
}
}
else if (ipstr[i]==“.“)
{
if (iPos>3) return false;
ipstrSubs[iPos]=“\0“;
count++;
iPos = 0;
}
else return false;
if (iPos==0)
{
if (atoi(ipstrSubs)<0||atoi(ipstrSubs)>255)
return false;
memset(ipstrSubs,“\0“,4);
}
i++;
}
if (count!=3) return false;
memset(m_CurWSNADDR,0,sizeof(m_CurWSNADDR));
strcpy(m_CurWSNADDR,"WSNADDR=//");
strcat(m_CurWSNADDR,ipstr);
strcat(m_CurWSNADDR,":");
if (atoi(port)>1024)
{
strcat(m_CurWSNADDR,port);
}
else return false;
return true;
}
char* CTuxCall::GetErrorMessage()
{
return ErrMsg;
}
char* CTuxCall::GetCurWSNAddr()
{
return m_CurWSNADDR;
}
char * CTuxCall::GetResultData()
{
return m_RecBuff;
}
测试程序
服务程序
#include
#include "transmit.h"
#include
int tpsvrinit(int argc,char** argv)
{
userlog("服务转发器transmitsrv启动成功.\r\n");
printf("服务转发器transmitsrv启动成功.\r\n");
return 0;
}
void tpsvrdone()
{
userlog("服务转发器transmitsrv关闭成功.\r\n");
printf("服务转发器transmitsrv关闭成功.\r\n");
}
char* UpperCase(char* str)
{
int i = 0;
while(str!=0)
{
str = toupper(str);
i++;
}
return str;
}
char* LowerCase(char* str)
{
int i = 0;
while(str!=0)
{
str = tolower(str);
i++;
}
return str;
}
char * TrimStr(char * str,int size)
{
if(!str)
return "";
for(int i=size-1;i>=0;i--)
{
if(str==“ “)
str=0;
else
return str;
}
return str;
}
char* ltrim(char* str)
{
if(str == NULL) return str;
int len = strlen(str);
for(int i=0; i {
if(str != “ “)
{
memmove(str,&str,len-i);
str[len-i] = 0;
break;
}
else if(i == len-1)
{
str[0] = 0;
break;
}
}
return str;
}
char* rtrim(char* str)
{
if(str == NULL) return str;
int len = strlen(str);
for(int i=len-1; i>=0; i--)
{
if(str!= “ “)
{
str[i+1] = 0;
break;
}
}
return str;
}
char *trimstr(char *str)
{
rtrim(str);
ltrim(str);
return str;
}
///////////服务函数////////////////////////////////////////////////////////////////
//====================== TRANSMIT 服务处理========================================
//ProcessTRANSMIT函数负责解析客户端传递的参数,并决定该调用哪一个服务.
#if defined(__STDC__) || defined(__cplusplus)
void ProcessTRANSMIT(TPSVCINFO *rqst,long len,char* sname)
#else
void ProcessTRANSMIT(*rqst,&len,*sname)
TPSVCINFO *rqst;
long len;
char* sname;
#endif
{
//服务.....
}
//TRANSMIT:服务转发器,客户端的程序统一调用TRANSMIT,然后由TRANSMIT服务
//根据opcode调用相应的服务.
#if defined(__STDC__) || defined(__cplusplus)
void TRANSMIT(TPSVCINFO *rqst)
#else
void TRANSMIT(*rqst)
TPSVCINFO *rqst;
#endif
{
char sname[32+10];
long len=0;
ProcessTRANSMIT(rqst,len,sname);
tpforward(sname,rqst->data,rqst->len,0);
tpreturn(TPSUCCESS,0,rqst->data,len,0);
}
//=====================TRANSMIT 服务处理结束=========================================
//======================== 测试用的服务 HelloWord ==================================
#if defined(__STDC__) || defined(__cplusplus)
void HelloWord(TPSVCINFO *rqst)
#else
void HelloWord(*rqst)
TPSVCINFO *rqst;
#endif
{
//数据格式:操作码(16位)用户名(32)
char opcode[17]={0};
char username[33]={0};
char* pBuf;
int len;
char retMsg[1024]={0};
int retFlag = 0;
printf("HelloWord: The Service HelloWord get request !\r\n");
memset(opcode,0,sizeof(opcode));
memset(username,0,sizeof(username));
memset(retMsg,0,sizeof(retMsg));
strncpy(opcode,rqst->data,16);
strncpy(username,rqst->data+16,32);
printf("HelloWord: [%s]\r\n",rqst->data);
printf("HelloWord: opcode = %s, UserName= %s\r\n",trimstr(opcode),trimstr(username));
if (!strcmp(opcode,"GetTime"))
{
time_t timer;
struct tm *tblock;
/* gets time of day */
timer = time(NULL);
/* converts date/time to a structure */
tblock = localtime(&timer);
printf("Local time is: %s", asctime(tblock));
sprintf(retMsg,"Now, Local time is: %s",asctime(tblock));
retFlag = 1;
}
else if (!strcmp(opcode,"Hello"))
{
printf("%s: First thanks. And welcome to use tuxedo .\r\n",username);
sprintf(retMsg,"%s: First thanks. And welcome to use tuxedo .\r\n",username);
retFlag = 1;
}
else
{
sprintf(retMsg,"[%s] %s",opcode,"无效的操作码!");
}
len = strlen(retMsg) + 1;
pBuf = tpalloc("CARRAY",NULL,len);
if(pBuf == 0)
{
tpreturn(TPFAIL,0,0,0,0);
}
else
{
strcpy(pBuf,retMsg);
if (retFlag==1){
tpreturn(TPSUCCESS,0,pBuf,len,0);
}else
{
tpreturn(TPFAIL,0,pBuf,len,0);
}
}
}
/////////////////// HelloWorld 结束 /////////////////////////////////////
客户端测试
gTuxCall.SetClientInfo("zlwen","Test->GetTime");
if (gTuxCall.SetWSNAddr("//192.168.1.7:44321"))
{
ShowMessage(gTuxCall.GetCurWSNAddr());
}
else
{
ShowMessage(gTuxCall.GetErrorMessage());
}
int inLen = gTuxCall.SetSendBuf("%-32s%-16s","GetTime","TestName");
//SetSendBuf的使用方法通printf().
int outLen = 0;
if (gTuxCall.Invoke("HelloWord",inLen,outLen))
{
ShowMessage(gTuxCall.GetResultData());
}
else
{
ShowMessage(gTuxCall.GetErrorMessage());
}
总结
本程序在C++ Builder 5.0上通过测试.有什么问题欢迎通过邮件联系.