windows下tuxedo开发

  1. 安装
    在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=
  2. 设置环境变量
    修改环境path,tuxedo的可执行文件路径;D:/bea/tuxedo8.1/bin
    TUXDIR=D:/bea/tuxedo8.1
    TUXCONFIG=%APPDIR%/tuxconfig
  3. 编写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
    上面的目录根据自己的情况修改。
  4. 编辑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
  5. 编译ubb
    运行cmd命令,进入控制台,进入D:/bea/tuxedo8.1/apps/simpapp目录:
    先后运行setenv命令,运行上面编辑的脚本setenv.cmd
    然后运行tmloadcf -y ubb编译ubb文件
    如果编译有错误,根据差错信息修改ubb,解决问题。

  6. 编程准备
    由于后面程序中需要用到一个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
  7. 编写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编译服务端程序
  8. 编辑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
  9. 运行,测试
    执行tmboot -y命令,启动tuxedo服务
    在命令行下运行clien 1,看是否有结果返回
    客户端程序和服务端程序都很简单,相信大家一下就能看明白。

你可能感兴趣的:(windows下tuxedo开发)