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


C++ socket_t::bind方法代码示例

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


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

示例1: Listen

void OTSocket::Listen(const OTString &strBind)
{
	if (NULL != m_pSocket)
		delete m_pSocket;
//	m_pSocket = NULL;
	m_pSocket = new zmq::socket_t(*m_pContext, ZMQ_REP);  // RESPONSE socket (Request / Response.)
	OT_ASSERT_MSG(NULL != m_pSocket, "OTSocket::Listen: new zmq::socket(context, ZMQ_REP)");
	
	OTString strTemp(strBind); // In case m_strBindPath is what was passed in. (It happens.)
	m_strBindPath.Set(strTemp); // In case we have to close/reopen the socket to finish a send/receive.
	
	// ------------------------
	//  Configure socket to not wait at close time
    //
	const int linger = 0; // close immediately
	m_pSocket->setsockopt (ZMQ_LINGER, &linger, sizeof (linger));
    /*
     int zmq_setsockopt (void *socket, int option_name, const void *option_value, size_t option_len);
     
     Caution: All options, with the exception of ZMQ_SUBSCRIBE, ZMQ_UNSUBSCRIBE and ZMQ_LINGER, only take effect for subsequent socket bind/connects.     
     */
    
	// ------------------------
    
	m_pSocket->bind(strBind.Get());
}
开发者ID:seanmerriam,项目名称:Open-Transactions,代码行数:26,代码来源:xmlrpcxx_server.cpp

示例2: Sensor

	SampleSensor::SampleSensor( VaneID specificId, SensorStaticAssetParams& params, DynamicAssetParams& dynamicParams )
		: Sensor(specificId, params, dynamicParams)
	{
		
		//Get the current IP address
		String ip;
		if(!getMyIP(ip)) {
			LogMessage("Failed to get IP", kLogMsgError);
			running = false;
		}
		else {
			LogMessage(ip);

			ipaddr = ip;
			running = true;

			//Bind to the computer's IP adress
			socket_.init(context_, ZMQ_PAIR);
			socket_.bind("tcp://" + ip + ":9000");

			LogMessage("Connected", kLogMsgSpecial);
		}

		frame = 0;
		sendRate = 15;
		quality_factor = 85;

		
		//cast to our specific type of asset params, and grab data 
		const SampleSensorStaticAssetParams& sampleParams = static_cast<const SampleSensorStaticAssetParams&>( params );
		m_sampleIntData = sampleParams.m_intData;
	}
开发者ID:jgstorms,项目名称:ANVEL-Android-Plugin,代码行数:32,代码来源:SampleSensor.cpp

示例3: bad_alloc

    comm_handler(config_param_t &cparam):
      zmq_ctx(1),
      msgq(zmq_ctx, ZMQ_PULL),
      taskq(zmq_ctx, ZMQ_PUSH),
      conn_sock(zmq_ctx, ZMQ_PULL),
      shutdown_sock(zmq_ctx, ZMQ_PULL),
      router_sock(zmq_ctx, ZMQ_ROUTER),
      monitor_sock(zmq_ctx, ZMQ_PAIR),
      pub_sendpull(zmq_ctx, ZMQ_PULL),
      pubstart_pull(zmq_ctx, ZMQ_PULL),
      suberq(zmq_ctx, ZMQ_PUSH),
      subpull(zmq_ctx, ZMQ_PULL),
      pub_sock(zmq_ctx, ZMQ_PUB),
      sub_sock(zmq_ctx, ZMQ_SUB),
      id(IDE2I(cparam.id)),
      ip(cparam.ip),
      port(cparam.port),
      accept_conns(cparam.accept_conns){
      pthread_mutex_init(&sync_mtx, NULL);
      try{	
        msgq.bind(MSGQ_ENDP);
        taskq.bind(TASKQ_ENDP);
        conn_sock.bind(CONN_ENDP);
        shutdown_sock.bind(SHUTDOWN_ENDP);
        pub_sendpull.bind(PUB_SEND_ENDP);
        pubstart_pull.bind(PUB_START_ENDP);
        suberq.bind(SUBER_Q_ENDP);
        subpull.bind(SUB_PULL_ENDP);
      }catch(zmq::error_t &e){
        LOG(DBG, stderr, "Failed to bind to inproc socket: %s\n", e.what());
        throw std::bad_alloc();
      }

      pthread_mutex_lock(&sync_mtx);
      errcode = 0;
      int ret = pthread_create(&pthr, NULL, start_handler, this);
      if(ret != 0) throw std::bad_alloc();
      pthread_mutex_lock(&sync_mtx); //cannot return until comm thread starts running
      pthread_mutex_unlock(&sync_mtx);
      if(errcode) throw std::bad_alloc();
    }
开发者ID:jinliangwei,项目名称:CommTest,代码行数:41,代码来源:comm_handler.hpp

示例4: _bind_tcp

uint16_t _bind_tcp(zmq::socket_t & sock, const std::string & ip, uint16_t port) {
    std::ostringstream ep;
    ep <<  "tcp://" << ip <<  ":";
    if (port == 0) {
        ep << "*";
    } else {
        ep << port;
    }
    DLOG(INFO) << "ZMQ binding endpoint " << ep.str();

    sock.bind(ep.str().c_str());
    if (port == 0) {
        const std::string endpoint = _get_zmq_last_endpoint(sock);
        uint16_t out_port = 0;
        _try_zmq_endpoint_get_port(endpoint, out_port);
        return out_port;
    }
    return port;
}
开发者ID:jpraher,项目名称:ipython-xlang-kernel,代码行数:19,代码来源:kernel.cpp

示例5: SOMException

/**
This function compactly allows binding a ZMQ socket to inproc address without needing to specify an exact address.  The function will try binding to addresses in the format: inproc://inputBaseString.inputExtensionNumberAsString and will try repeatedly while incrementing inputExtensionNumber until it succeeds or the maximum number of tries has been exceeded.
@param inputSocket: The ZMQ socket to bind
@param inputBaseString: The base string to use
@param inputExtensionNumber: The extension number to start with
@param inputMaximumNumberOfTries: How many times to try binding before giving up
@return: A tuple of form <connectionString ("inproc://etc"), extensionNumberThatWorked>

@throws: This function can throw exceptions if the bind call throws something besides "address taken" or the number of tries are exceeded
*/
std::tuple<std::string, int> pylongps::bindZMQSocketWithAutomaticAddressGeneration(zmq::socket_t &inputSocket, const std::string &inputBaseString, int inputExtensionNumber, unsigned int inputMaximumNumberOfTries)
{
bool socketBindSuccessful = false;
std::string connectionString;
int extensionNumber = inputExtensionNumber;

for(int i=0; i<inputMaximumNumberOfTries; i++)
{
try //Attempt to bind the socket
{
connectionString = std::string("inproc://") + inputBaseString + std::string(".") + std::to_string(extensionNumber);
inputSocket.bind(connectionString.c_str());
socketBindSuccessful = true; //Got this far without throwing
break;
}
catch(const zmq::error_t &inputZMQError)
{
if(inputZMQError.num() == EADDRINUSE)
{
extensionNumber++; //Increment so the next attempted address won't conflict
}
else
{
throw SOMException(std::string("Error binding socket") + connectionString + std::string("\n"), ZMQ_ERROR, __FILE__, __LINE__);
}
}

}

if(!socketBindSuccessful)
{
throw SOMException(std::string("Socket bind did not succeed in ") + std::to_string(inputMaximumNumberOfTries) + std::string(" attempts\n"), UNKNOWN, __FILE__, __LINE__);
}

return make_tuple(connectionString, extensionNumber);
}
开发者ID:NosDE,项目名称:pylonGPS,代码行数:46,代码来源:utilityFunctions.cpp

示例6: Transport

 Transport()
   : context_(1), requestSocket_(context_, ZMQ_REQ), replySocket_(context_, ZMQ_REP)
 {
   replySocket_.bind("tcp://*:5555");
   requestSocket_.connect("tcp://localhost:5555");
 }
开发者ID:Kelvin945,项目名称:stateline,代码行数:6,代码来源:transport.cpp

示例7: bind

 void bind(::zmq::socket_t& socket, const AddressList& address_list)
 {
   typedef typename AddressList::const_iterator iter_t;
   for (iter_t it = address_list.begin(); it != address_list.end(); ++it)
     socket.bind(it->c_str());
 }
开发者ID:yuijo,项目名称:miu-core,代码行数:6,代码来源:utility.hpp


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