TCP Manual

内容表

关于

The Transmission Control Protocol allows to create network connections to remote machines in order to send data. The maxon::NetworkTcpInterface is used to create either an outgoing connection to send TCP/IP data or to create an server to receive such data.

注意
The TCP interface uses an AioService. See maxon::AioServiceInterface .

NetworkTcpInterface

The maxon::NetworkTcpInterface provides these functions:

NetworkTcpServerInterface

The maxon::NetworkTcpServerInterface defines a TCP server that reacts to incoming TCP connections:

// This example starts a TCP server. The behaviour on an incoming // connection is defined with the given callback function.

// create AioService g_tcpIoService = maxon::AioServiceRef::Create() iferr_return ; g_tcpIoService.Start() iferr_return ;

// create and start server auto localAddr = maxon :: NetworkIpAddrPort ( maxon :: WILDCARD_IPV4_ADDRESS , 2000); g_tcpServer = maxon ::NetworkTcpInterface::CreateServer(localAddr, TCPServerCallback, g_tcpIoService, maxon :: JOBQUEUE_CURRENT ) iferr_return ; g_tcpServer.Start() iferr_return ;

For an example on the callback function see below.

NetworkTcpConnectionInterface

The maxon::NetworkTcpConnectionInterface represents an established TCP connection. This connection can receive data from the remote machine or send data to that machine.

// This example shows a callback function that defines the behaviour of a TCP server for an incoming TCP connection.
static maxon::Result<void> TCPServerCallback( maxon::Result<void> res, maxon::NetworkTcpConnectionRef connection) { iferr_scope ;

// print remote address const maxon::NetworkIpAddrPort remote = connection.GetRemoteAddress(); DiagnosticOutput ( "Connected with @" , remote);

// define receive callback connection.Receive( []( maxon::Result<void> res, maxon::AioBuffer buffer) -> maxon::Result<void> { iferr_scope ; // print received message const maxon::String message { buffer }; DiagnosticOutput ( "Message: @" , message); return maxon::OK ; }) iferr_return ; return maxon::OK ; }

// This example opens a TCP connection to a remote host and sends some data.

// prepare AioServiceRef const maxon::AioServiceRef service = maxon::AioServiceRef::Create() iferr_return ; service.Start() iferr_return ;

// open TCP connection maxon ::NetworkTcpInterface::OpenOutgoingConnection(remoteAddr, []( maxon ::Result< void >, maxon ::NetworkTcpConnectionRef connection) -> maxon ::Result< void > { iferr_scope ;

// prepare message maxon::CString messageCStr( "Test Message" ); maxon::AioBuffer buffer; for ( const maxon::Char c: messageCStr) { iferr (buffer. Append (c)) err.DbgStop(); }

// send message return connection.Send(std::move(buffer)); }, service, maxon::JOBQUEUE_CURRENT ) iferr_return ;

延伸阅读

maxon
The maxon namespace contains all declarations of the MAXON API.
定义: c4d_basedocument.h:15
maxon::JOBQUEUE_CURRENT
static const JobQueueInterface::Current JOBQUEUE_CURRENT
Equivalent to calling GetDestinationQueue(), you just save a function call.
定义: jobqueue.h:361
maxon::String
定义: string.h:1197
maxon::OK
return OK
定义: apibase.h:2532
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::BaseArray< Char >
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::Result< void >
maxon::NetworkIpAddrPort
定义: network_ip_addr.h:438
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
定义: basearray.h:569
iferr_scope
#define iferr_scope
定义: resultbase.h:1343
maxon::WILDCARD_IPV4_ADDRESS
static const WILDCARD_IPV4_ADDRESS_TYPE WILDCARD_IPV4_ADDRESS
定义: network_ip_addr.h:45
maxon::Char
char Char
signed 8 bit character
定义: apibase.h:180
iferr
#define iferr(...)
定义: errorbase.h:380
maxon::CString
定义: string.h:1436

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1