server.c
上传用户:sdtbys
上传日期:2009-12-06
资源大小:13k
文件大小:2k
- #include <stdio.h>
- #include "pk.h"
- B_STRU1 b_data1,*b_datap1;
- B_STRU2 b_data2,*b_datap2;
- F_STRU1 f_data1,*f_datap1;
- F_STRU2 f_data2,*f_datap2;
- main()
- {
- int fsockid,bsockid;
- int ret,len;
- char midbuf[500];
- b_datap1=&b_data1;
- b_datap2=&b_data2;
- f_datap1=&f_data1;
- f_datap2=&f_data2;
- daemon_procedure(1);
- fsockid=server_socket("",9898);
- while(1)
- {
- ret=accept_procdure(&fsockid);
- memset(midbuf,0,sizeof(midbuf));
- if (ret==0)
- {
- #ifdef DEBUG
- WriteLog("接受请求开始");
- #endif
- if((len=read_socket(fsockid,midbuf,FLEN1))!=FLEN1)
- {
- memset(f_datap2,0,FLEN2);
- strcpy(f_datap2->retcode,"9001");
- memset(midbuf,0,sizeof(midbuf));
- tscanf(midbuf,F_FMT2,F_VAR2);
- write_socket(fsockid,midbuf,FLEN2);
- break;
- }
- #ifdef DEBUG
- WriteLog("midbufn");
- WriteLog("%s",midbuf);
- #endif
- if ((ret=tscanf(midbuf,F_FMT1,F_VAR1))!=0)
- {
- fprintf(stderr,"ret=%dn",ret);
- WriteLog("%d",ret);
- memset(f_datap2,0,FLEN2);
- strcpy(f_datap2->retcode,"9002");
- memset(midbuf,0,sizeof(midbuf));
- tscanf(midbuf,F_FMT2,F_VAR2);
- write_socket(fsockid,midbuf,FLEN2);
- break;
- }
- #ifdef DEBUG
- WriteLog("apcode=[%4s] acno=[%15s] pktyp=[%1s]",f_datap1->apcode,f_datap1->acno,f_datap1->pktyp);
- WriteLog("fore1=[%16s] fore2=[%16s] mach=[%8s] chip=[%6s]",f_datap1->fore1,f_datap1->fore2,f_datap1->mach,f_datap1->chip);
- WriteLog("bk=[%48s] mmcode=[%12s]",f_datap1->bk,f_datap1->mmcode);
- WriteLog("acdate=[%8s] vchdate=[%8s] amount=[%19.2lf] limit=[%19.2lf]",f_datap1->acdate,f_datap1->vchdate,f_datap1->amount,f_datap1->limit);
- WriteLog("vchtyp=[%2s] vchstart=[%8ld] vchend=[%8ld]",f_datap1->vchtyp,f_datap1->vchstart,f_datap1->vchend);
- WriteLog("tlid=[%4s] name=[%10s] idcard=[%20s]",f_datap1->tlid,f_datap1->name,f_datap1->idcard);
- #endif
-
- break;
- }
- }
- close(fsockid);
- exit(0);
- }
- int reterr(int fsockid,char *errcode)
- {
- char midbuf[100];
- memset(f_datap2,0,FLEN2);
- strncpy(f_datap2->retcode,errcode,4);
- memset(f_datap2->bk,'0',48);
- memset(midbuf,0,sizeof(midbuf));
- tprintf(midbuf,F_FMT2,F_VAR2);
- WriteLog("返回前台:%s",midbuf);
- write_socket(fsockid,midbuf,strlen(midbuf));
- return(0);
- }