ace_udp_client_dll.cpp

来自「本源码采用ACE中间件开发包实现C/S通信服务」· C++ 代码 · 共 54 行

CPP
54
字号
#ifndef DLL_FILE
#define DLL_FILE
#endif

#define DATA_BUFFER_SIZE 1024
#define SIZE_DATA 29
#include "ACE_UDP_CLIENT_DLL.H"

Client::Client(char * remote_host):remote_addr_(remote_host),local_addr_((u_short)0),local_(local_addr_)
	{
		data_buf = new char[DATA_BUFFER_SIZE];
	}
Client::~Client()
{

}
 int Client::accept_data()
 {
	 if(local_.recv(data_buf,SIZE_DATA,remote_addr_)!=-1)	
		{
			
			ACE_DEBUG((LM_DEBUG, "Data received from remote server %s was: %s \n" ,
				
				remote_addr_.get_host_name(), data_buf));
			
			return 0;	
		}
		
		else
			
			return -1;
		
 }

 int  Client::send_data()
 {
	 	ACE_DEBUG((LM_DEBUG,"Preparing to send data to server %s:%d\n",
			
			remote_addr_.get_host_name(),remote_addr_.get_port_number()));
		
		ACE_OS::sprintf(data_buf,"Client says hello");
		
		
		while(local_.send(data_buf,ACE_OS::strlen(data_buf),remote_addr_)!=-1)
			
		{
				
			break;
			
		}
			
		return -1;
		
 }

⌨️ 快捷键说明

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