当前位置: 首页>>代码示例>>C++>>正文


C++ TcpServer::port方法代码示例

本文整理汇总了C++中TcpServer::port方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpServer::port方法的具体用法?C++ TcpServer::port怎么用?C++ TcpServer::port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TcpServer的用法示例。


在下文中一共展示了TcpServer::port方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void InetWvIn :: listen( int port, unsigned int nChannels,
                         Stk::StkFormat format, Socket::ProtocolType protocol )
{
    mutex_.lock();

    if ( connected_ ) delete soket_;

    if ( nChannels < 1 ) {
        oStream_ << "InetWvIn()::listen(): the channel argument must be greater than zero.";
        handleError( StkError::FUNCTION_ARGUMENT );
    }

    if ( format == STK_SINT16 ) dataBytes_ = 2;
    else if ( format == STK_SINT32 || format == STK_FLOAT32 ) dataBytes_ = 4;
    else if ( format == STK_FLOAT64 ) dataBytes_ = 8;
    else if ( format == STK_SINT8 ) dataBytes_ = 1;
    else {
        oStream_ << "InetWvIn(): unknown data type specified!";
        handleError( StkError::FUNCTION_ARGUMENT );
    }
    dataType_ = format;

    unsigned long bufferBytes = bufferFrames_ * nBuffers_ * nChannels * dataBytes_;
    if ( bufferBytes > bufferBytes_ ) {
        if ( buffer_) delete [] buffer_;
        buffer_ = (char *) new char[ bufferBytes ];
        bufferBytes_ = bufferBytes;
    }

    data_.resize( bufferFrames_, nChannels );
    lastFrame_.resize( 1, nChannels, 0.0 );

    bufferCounter_ = 0;
    writePoint_ = 0;
    readPoint_ = 0;
    bytesFilled_ = 0;

    if ( protocol == Socket::PROTO_TCP ) {
        TcpServer *socket = new TcpServer( port );
        oStream_ << "InetWvIn:listen(): waiting for TCP connection on port " << socket->port() << " ... ";
        handleError( StkError::STATUS );
        fd_ = socket->accept();
        if ( fd_ < 0) {
            oStream_ << "InetWvIn::listen(): Error accepting TCP connection request!";
            handleError( StkError::PROCESS_SOCKET );
        }
        oStream_ << "InetWvIn::listen(): TCP socket connection made!";
        handleError( StkError::STATUS );
        soket_ = (Socket *) socket;
    }
    else {
        soket_ = new UdpSocket( port );
        fd_ = soket_->id();
    }

    connected_ = true;

    mutex_.unlock();
}
开发者ID:ilearain,项目名称:stk,代码行数:59,代码来源:InetWvIn.cpp


注:本文中的TcpServer::port方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。