- 安裝
在winxp上安裝tuxedo8.1,在最後得到一個license檔案,命名為lic.txt,拷貝到D:/bea/tuxedo8.1/udataobj目錄下,同時在選擇license目錄為該目錄。
我這兒有一個license檔案,內容如下,可以將這些內容拷貝到一個文字檔中,然後儲存這個文字檔名為lic.txt,拷貝到udataobj目錄中。
[BEA TUXEDO]
DEVELOPERS=5
LICENSEE=China CNC
SERIAL=650522264138-1511336328750
TYPE=SDK
USERS=5
VERSION=8.1
SIGNATURE=MC4CFQCUgAb0mFiQJ6pIUCnJZ5TmPha2WAIVALz6sU+ZHPtRMmNXf0ofU9rpT3Gs[LINK ENCRYPTION]
DEVELOPERS=5
LICENSEE=China CNC
SERIAL=650522264138-1511336328750
STRENGTH=56
TYPE=SDK
USERS=5
VERSION=8.1
SIGNATURE=MC0CFDo0wo+LR5JfJKoQ5vgLnCRMfVUYAhUArx+kLwb6qRFeWuJsmNs5P3Gmvb4=
[PK ENCRYPTION]
DEVELOPERS=5
LICENSEE=China CNC
SERIAL=650522264138-1511336328750
STRENGTH=56
TYPE=SDK
USERS=5
VERSION=8.1
SIGNATURE=MC0CFAriv6cffzHh9CQUZIwBazNhfQ8VAhUAs/K962UPBb1mxRgw7cLbMz88EJs=
[PK SIGNATURE]
DEVELOPERS=5
LICENSEE=China CNC
SERIAL=650522264138-1511336328750
STRENGTH=56
TYPE=SDK
USERS=5
VERSION=8.1
SIGNATURE=MCwCFBm04mN7qZiqyfjBNuDZVP78dpxPAhRfZqq4bvln1/3knANn8G7L/mjuWw==
[SNMP]
DEVELOPERS=5
LICENSEE=China CNC
SERIAL=650522264138-1511336328750
TYPE=SDK
USERS=5
VERSION=8.1
SIGNATURE=MC0CFBm04mN7qZiqyfjBNuDZVP78dpxPAhUAnLiZmIMgZbSNV4YJN1CIi/wHa3c=
[SSL ENCRYPTION]
DEVELOPERS=5
LICENSEE=China CNC
SERIAL=650522264138-1511336328750
STRENGTH=56
TYPE=SDK
USERS=5
VERSION=8.1
SIGNATURE=MC0CFBm04mN7qZiqyfjBNuDZVP78dpxPAhUAyHG9UfCabk+DOInlUU+cgbuJVYc=
- 設定環境變數
修改環境path,tuxedo的可執行檔路徑;D:/bea/tuxedo8.1/bin
TUXDIR=D:/bea/tuxedo8.1
TUXCONFIG=%APPDIR%/tuxconfig
- 編寫setenv.cmd指令碼
setenv.cmd的內容如下,編輯好了之後,存放到D:/bea/tuxedo8.1/apps/simpapp目錄。
set TUXDIR=D:/bea/tuxedo8.1
set APPDIR=D:/bea/tuxedo8.1/apps/simpapp
set PATH=%TUXDIR%/bin;%APPDIR%;%PATH%
set TUXCONFIG=%APPDIR%/tuxconfig
VCVARS32.bat
上面的目錄根據自己的情況修改。
- 編輯ubbconfig
編譯檔案ubb,然後存放到目錄D:/bea/tuxedo8.1/apps/simpapp中,內容如下:
# (c) 2003 BEA Systems, Inc. All Rights Reserved.
#ident "@(#) samples/atmi/simpapp/ubbsimple $Revision: 1.5 $"
#Skeleton UBBCONFIG file for the TUXEDO Simple Application.
#Replace the <bracketed> items with the appropriate values.
*RESOURCES
#Example:
IPCKEY 123456
DOMAINID chenli
MASTER chenli
MAXACCESSERS 50
MAXSERVERS 5
MAXSERVICES 10
MAXGTT 5
MODEL SHM
LDBAL N
*MACHINES
DEFAULT:
APPDIR="D:/bea/tuxedo8.1/apps/simpapp"
TUXCONFIG="D:/bea/tuxedo8.1/apps/simpapp/tuxconfig"
TUXDIR="D:/bea/tuxedo8.1"
ULOGPFX="D:/bea/tuxedo8.1/apps/simpapp/log.txt"
MAXWSCLIENTS=40
#Example:
# APPDIR="/home/me/simpapp"
# TUXCONFIG="/home/me/simpapp/tuxconfig"
# TUXDIR="/usr/tuxedo"
#<Machine-name>
CHENLI LMID=chenli
#Example:
#beatux LMID=chenli
*GROUPS
GROUP1 LMID=chenli GRPNO=1 OPENINFO=NONE*SERVERS
DEFAULT:
CLOPT="-A"
simpserv SRVGRP=GROUP1 SRVID=1 MIN = 1 MAX = 5
*SERVICES
TOUPPER
- 編譯ubb
運行cmd命令,進入控制台,進入D:/bea/tuxedo8.1/apps/simpapp目錄:
先後運行setenv命令,運行上面編輯的指令碼setenv.cmd
然後運行tmloadcf -y ubb編譯ubb檔案
如果編譯有錯誤,根據差錯資訊修改ubb,解決問題。
- 編程準備
由於後面程式中需要用到一個data.h標頭檔,儲存在D:/bea/tuxedo8.1/apps/simpapp目錄,內容如下:#ifndef DATA_H
#define DATA_H
#define NAME_LENGTH 64
typedef struct trans_data
{
int age;
char name[NAME_LENGTH];
}trans_data_t;
#endif
- 編寫server端程式simpserv.c
編輯檔案simpserv.c,存放到D:/bea/tuxedo8.1/apps/simpapp目錄,內容如下:
/* (c) 2003 BEA Systems, Inc. All Rights Reserved. */
/* Copyright (c) 1997 BEA Systems, Inc.
All rights reserved
THIS IS UNPUBLISHED PROPRIETARY
SOURCE CODE OF BEA Systems, Inc.
The copyright notice above does not
evidence any actual or intended
publication of such source code.
*/
/* #ident "@(#) samples/atmi/simpapp/simpserv.c $Revision: 1.5 $" */
#include <stdio.h>
#include <ctype.h>
#include <atmi.h> /* TUXEDO Header File */
#include <userlog.h> /* TUXEDO Header File */
#include "data.h"/* tpsvrinit is executed when a server is booted, before it begins
processing requests. It is not necessary to have this function.
Also available is tpsvrdone (not used in this example), which is
called at server shutdown time.
*/
int inc_count = 0;
#if defined(__STDC__) || defined(__cplusplus)
tpsvrinit(int argc, char *argv[])
#else
tpsvrinit(argc, argv)
int argc;
char **argv;
#endif
{
/* 如果沒有argc、argv一些編譯系統會有警告資訊. */
/* Some compilers warn if argc and argv aren't used. */
argc = argc;
argv = argv;
/* userlog 把tuxedo訊息寫入記錄檔中 */
/* userlog writes to the central TUXEDO message log */
userlog("Welcome to the simple server");
return(0);
}
/* This function performs the actual service requested by the client.
Its argument is a structure containing among other things a pointer
to the data buffer, and the length of the data buffer.
*/
#ifdef __cplusplus
extern "C"
#endif
void
#if defined(__STDC__) || defined(__cplusplus)
TOUPPER(TPSVCINFO *rqst) /*tuxedo服務名字TOUPPER*/
#else
TOUPPER(rqst)
TPSVCINFO *rqst;
#endif
{
int i;
int x;
trans_data_t buf_data;
char *data = "how are you?";
char *ref;
int len = strlen(data) + 1;
userlog("start proccess TOUPPER service");
ref = (char *)malloc(len);
strcpy(ref, data);
userlog("rqst->len=%d/n", rqst->len);
memcpy(&buf_data, rqst->data, sizeof(trans_data_t));
userlog("receive string:%s", rqst->data);
userlog("receive name:%s", buf_data.name);
userlog("receive age:%d", buf_data.age);
buf_data.age += 100;
memcpy(rqst->data, &buf_data, sizeof(trans_data_t));
//data = rqst->data;
/* Return the transformed buffer to the requestor. */
/* 設定返回用戶端buffer */
tpreturn(TPSUCCESS, 0, rqst->data, sizeof(trans_data_t), 0);
free(ref);
}
然後在控制台下執行命令buildserver -o simpserv -f simpserv.c -s TOUPPER編譯服務端程式
- 編輯client程式simpcl.c
編輯simpcl.c檔案,然後儲存到目錄D:/bea/tuxedo8.1/apps/simpapp,內容如下:
/* (c) 2003 BEA Systems, Inc. All Rights Reserved. */
/* Copyright (c) 1997 BEA Systems, Inc.
All rights reserved
THIS IS UNPUBLISHED PROPRIETARY
SOURCE CODE OF BEA Systems, Inc.
The copyright notice above does not
evidence any actual or intended
publication of such source code.
*/
/* #ident "@(#) samples/atmi/simpapp/simpcl.c $Revision: 1.5 $" */
#include <stdio.h>
#include "atmi.h" /* TUXEDO Header File */
#include "data.h"
#if defined(__STDC__) || defined(__cplusplus)
main(int argc, char *argv[])
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
trans_data_t buf_data;
char *sendbuf, *rcvbuf;
long sendlen, rcvlen;
int ret = 0;
if(argc != 2) {
(void) fprintf(stderr, "Usage: simpcl age(int)/n");
exit(1);
}
buf_data.age = atoi(argv[1]);
/* 作為tuxedo用戶端連入tuxedo System */
/* Attach to System/T as a Client Process */
if (tpinit((TPINIT *) NULL) == -1) {
(void) fprintf(stderr, "Tpinit failed/n");
exit(1);
}
sendlen = sizeof(trans_data_t);
strcpy(buf_data.name, "chenli");
//buf_data.age = 20;
//sendlen = strlen(argv[1]);
/* Allocate STRING buffers for the request and the reply */
/* 使用tpalloc申請string類型buffer作為請求和應答buffer */
if((sendbuf = (char *) tpalloc("CARRAY", NULL, sendlen+1)) == NULL) {
(void) fprintf(stderr,"Error allocating send buffer/n");
tpterm();
exit(1);
} if((rcvbuf = (char *) tpalloc("CARRAY", NULL, sendlen)) == NULL) {
(void) fprintf(stderr,"Error allocating receive buffer/n");
tpfree(sendbuf);
tpterm();
exit(1);
}
printf("sendlen=%d/n", sendlen);
memcpy(sendbuf, &buf_data, sendlen);
//(void) strcpy(sendbuf, argv[1]);
/* Request the service TOUPPER, waiting for a reply */
ret = tpcall("TOUPPER", (char *)sendbuf, sendlen, (char **)&rcvbuf, &rcvlen, (long)0);
(void) fprintf(stderr, "ret value = %d/n", ret);
/* 同步調用TOUPPER服務 */
if(ret < 0 ) {
printf("tpcall failed, tperrno=%ld, tperrtext=%s/n", tperrno, tpstrerror(tperrno));
(void) fprintf(stderr, "Can't send request to service TOUPPER/n");
(void) fprintf(stderr, "Tperrno = %d/n", tperrno);
(void) fprintf(stderr, "ret value = %d/n", ret);
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
exit(1);
}
memset(&buf_data, 0, sizeof(trans_data_t));
memcpy(&buf_data, rcvbuf, rcvlen);
printf("rcvlen=%d/n", rcvlen);
(void) fprintf(stdout, "Returned name: %s/n", buf_data.name);
(void) fprintf(stdout, "Returned age: %d/n", buf_data.age);
/* 使用tpfree釋放申請的請求和應答buffer空間 */
/* Free Buffers & Detach from System/T */
tpfree(sendbuf);
tpfree(rcvbuf);
/* 使用tpterm離開tuxedo System */
tpterm();
return(0);
}
在檔案所在目錄執行編譯命令buildclient -v -o client -f simpcl.c
- 運行,測試
執行tmboot -y命令,啟動tuxedo服務
在命令列下運行clien 1,看是否有結果返回
用戶端程式和服務端程式都很簡單,相信大家一下就能看明白。