⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 okc0.c

📁 分布式传输功能
💻 C
字号:
/*file:helloc0.c*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "hello.h"
#include "helloc.h"
#include <assert.h>

void main()
{

	RPC_STATUS status;
	unsigned char *pszUuid=NULL;
	unsigned char *pszProtocolSequence ="ncacn_np";
	unsigned char *pszNetworkAddress =NULL;
	unsigned char *pszEndpoint ="\\pipe\\hello0";
	unsigned char *pszOptions =NULL;
	unsigned char *pszStringBinding =NULL;
	unsigned char *pszString ="hello,RPC_Server!";
	short i=20;
	unsigned long ulCode;
	float num=10;
	float balance=100; 
	 int result=2;
	 	int tt=0;
		  FILE *fp;
	 operation uu={"101",'w',13};
	 

	 //初始化数据
	  char account_NO[10] ="101";
	  char trantype='d';
	 float a=0;

	 printf("请输入要执行的操作:形如101 w 1表示对帐号101取款金额为1\n");
	    scanf("%s",account_NO);
		strcpy(uu.account_number,account_NO);
		scanf("%c",&trantype);
		while(trantype==' ')
			scanf("%c",&trantype);
		uu.account_type=trantype;
		scanf("%f",&a);
		uu.amount=a;
	
	 
	   if((fp=fopen("loadbalancer","r"))==NULL)
	   {
		   printf("cannot open infile\n");
		   return;
	   }
	   fscanf(fp,"%d",&g_client);
	   fclose(fp);
	   if((fp=fopen("loadbalancer","w"))==NULL)
	   {
		   printf("cannot open infile\n");
		   return;
	   }
		tt=g_client;
		g_client++;
		fprintf(fp,"%d",g_client);
		fclose(fp);
		printf("本次操作将要在server%d上执行\n",tt%3);
        tt++;
		tt=tt%3;
	  
	 if((tt%3)==0)
		 strcpy(pszEndpoint,"\\pipe\\hello0");
	  if((tt%3)==1)
		 strcpy(pszEndpoint,"\\pipe\\hello1");
	 else if((tt%3)==2)
		 strcpy(pszEndpoint,"\\pipe\\hello2");
	

    
//	freopen("exection3.in","r",stdin);
	

	 //U uu;
	// myexe uu;
	// operation uu={"101",'w',13};
	// strcpy(uu.account_number,account_NO);
	// uu.account_type=trantype;
	// uu.amount=a;

	status =RpcStringBindingCompose(pszUuid,
	                             	pszProtocolSequence,
		                            pszNetworkAddress,
									 pszEndpoint,
									 pszOptions,
									 &pszStringBinding);
	printf("%s",pszStringBinding);

	status = RpcBindingFromStringBinding(pszStringBinding,
                                         &hello_IfHandle);
	printf("RpcBindingFromStringBinding returned: 0x%x\n", status);
	 if(status)
	{
		exit(status);
	}
 
   	//while(1)
	//{
		
		 
	 
	RpcTryExcept
	{
	
	//	HelloProc(i,pszString);
	//	printf("%s\n", pszString);
	//	add(&num);
	//	printf("%lf\n",num);
	//	getch();
	
		query(&uu,&balance);
		if(balance==1)
			printf("server%d says ok \n",tt);
	}
	RpcExcept(1)
	{
		ulCode =RpcExceptionCode();
		printf("Runtime reported exception 0x%lx =%ld \n",ulCode,ulCode);
	//	getch();
	}
	RpcEndExcept
	//}
    

	status=RpcStringFree(&pszStringBinding);
	if(status)
	{
		exit(status);
	}
	status=RpcBindingFree(&hello_IfHandle);
	if(status)
	{
		exit(status);
	}


	tt++;
		tt=tt%3;
	  //printf("%d",g_client);
	 if((tt%3)==0)
		 strcpy(pszEndpoint,"\\pipe\\hello0");
	  if((tt%3)==1)
		 strcpy(pszEndpoint,"\\pipe\\hello1");
	 else if((tt%3)==2)
		 strcpy(pszEndpoint,"\\pipe\\hello2");
	

    
//	freopen("exection3.in","r",stdin);
	

	 //U uu;
	// myexe uu;
	// operation uu={"101",'w',13};
	// strcpy(uu.account_number,account_NO);
	// uu.account_type=trantype;
	// uu.amount=a;

	status =RpcStringBindingCompose(pszUuid,
	                             	pszProtocolSequence,
		                            pszNetworkAddress,
									 pszEndpoint,
									 pszOptions,
									 &pszStringBinding);
	printf("%s",pszStringBinding);

	status = RpcBindingFromStringBinding(pszStringBinding,
                                         &hello_IfHandle);
	printf("RpcBindingFromStringBinding returned: 0x%x\n", status);
	 if(status)
	{
		exit(status);
	}
 
   	//while(1)
	//{
	
		 
	 
	RpcTryExcept
	{
	
	//	HelloProc(i,pszString);
	//	printf("%s\n", pszString);
	//	add(&num);
	//	printf("%lf\n",num);
	//	getch();
	
		query(&uu,&balance);
		if(balance==1)
			printf("server%d says ok \n",tt);
	}
	RpcExcept(1)
	{
		ulCode =RpcExceptionCode();
		printf("Runtime reported exception 0x%lx =%ld \n",ulCode,ulCode);
	//	getch();
	}
	RpcEndExcept
	//}
    

	status=RpcStringFree(&pszStringBinding);
	if(status)
	{
		exit(status);
	}
	status=RpcBindingFree(&hello_IfHandle);
	if(status)
	{
		exit(status);
	}	
    



     	tt++;
		tt=tt%3;
	  //printf("%d",g_client);
	 if((tt%3)==0)
		 strcpy(pszEndpoint,"\\pipe\\hello0");
	  if((tt%3)==1)
		 strcpy(pszEndpoint,"\\pipe\\hello1");
	 else if((tt%3)==2)
		 strcpy(pszEndpoint,"\\pipe\\hello2");
	

    
//	freopen("exection3.in","r",stdin);
	

	 //U uu;
	// myexe uu;
	// operation uu={"101",'w',13};
	// strcpy(uu.account_number,account_NO);
	// uu.account_type=trantype;
	// uu.amount=a;

	status =RpcStringBindingCompose(pszUuid,
	                             	pszProtocolSequence,
		                            pszNetworkAddress,
									 pszEndpoint,
									 pszOptions,
									 &pszStringBinding);
	printf("%s",pszStringBinding);

	status = RpcBindingFromStringBinding(pszStringBinding,
                                         &hello_IfHandle);
	printf("RpcBindingFromStringBinding returned: 0x%x\n", status);
	 if(status)
	{
		exit(status);
	}
 
   	//while(1)
	//{
	
		printf("%s %c %.2f",uu.account_number,uu.account_type,uu.amount);	 
	 
	RpcTryExcept
	{

		result=transact(&uu,&balance);
	if(balance>=0)
		{
		  printf(" success ");
		  printf("balance:%.2lf\n",balance);
		}
		else if(balance==-1)
			printf("无此帐户\n");
		else if(balance==-2)
			printf("余额不足\n");
		//getch();
		printf("请按任意建结束");
	    getch();
		Shutdown();
	}
	RpcExcept(1)
	{
		ulCode =RpcExceptionCode();
		printf("Runtime reported exception 0x%lx =%ld \n",ulCode,ulCode);
	//	getch();
	}
	RpcEndExcept
	//}
    

	status=RpcStringFree(&pszStringBinding);
	if(status)
	{
		exit(status);
	}
	status=RpcBindingFree(&hello_IfHandle);
	if(status)
	{
		exit(status);
	}
	exit(0);
	printf("exection3.in操作执行完毕");
	getch();
	//Shutdown();
}//end main()
//void __RPC_FAR * __RPC_API midl_user_allocate(size_t len)

void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
{
	return(malloc(len));
}
//void __RPC_API midl_user_free(void __RPC_FAR  *ptr)
void __RPC_USER midl_user_free( void __RPC_FAR *ptr)
{
	free(ptr);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -