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


C++ UdpSocket::Bind方法代码示例

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


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

示例1: main

int main()
{

    UdpDriver  drv;
    drv.Init(1);
    UdpSocketHandlerSharedPtr pHdlr(new PingPangUdpHandler());
    drv.SetHandler(pHdlr);
    UdpSocket svr;
    if(svr.Init())
    {
        return -1;
    }
    if(svr.Bind(SockAddress(1234,"127.0.0.1")))
    {
        return -1;
    }
    drv.AddSocket(svr.GetFD());
    while(1)
    {
        if(drv.Loop(1,10) < 0)
        {
            return -1;
        }
    }
    return 0;
}
开发者ID:jj4jj,项目名称:ssukits,代码行数:26,代码来源:UdpServer.cpp

示例2: runTimeClient

void runTimeClient (void *ptr) {

	int port = *ssi_pcast (int, ptr);

	/*TcpSocket sock;
	sock.create ();
	printf ("request framework time");
	ssi_size_t time;
	while (!sock.connect ("localhost", port)) {
		printf (".");
		sleep_ms (100);
	}
	int n_recv = sock.recv (&time, sizeof (time));
	if (n_recv > 0) {
		printf ("\nreceived time in ms: %u\n", time);
	}

	sock.shutdown (SD_BOTH);
	sock.close ();	*/

	UdpSocket sock;
	sock.Bind (IpEndpointName ("localhost", 459234));

	printf ("request framework time\n");
	char msg = 0;
	IpEndpointName server ("localhost", port);
	sock.SendTo (server, &msg, 1);
	ssi_size_t time;
	int recv = sock.ReceiveFrom (server, ssi_pcast (char, &time), sizeof (ssi_size_t));
	if (recv != -1) {
		printf ("\nreceived time in ms: %u\n", time);
	}

	Sleep (2000);
}
开发者ID:hihiy,项目名称:IntelliVoice,代码行数:35,代码来源:Main_.cpp

示例3: main

int main(){
	if(!winSockDll.Init()){
		std::cout<<"Couldn't load winsock"<<std::endl;
		system("pause");
		return 1;
	}
	connections = (Address*)calloc(64, sizeof(Address));

	addr = Address("127.0.0.1", 2222);
	sConnect = UdpSocket();
	sConnect.Bind(addr);
	std::cout << "Server started..." << std::endl;

	char* buffer = new char[512];
	bool clientexist = false;
	while(true){
		clientexist = false;
		ZeroMemory(buffer, 512);
		sConnect.Receive(buffer, 512, &storeAddr);
		for(int i = 0; i < Counter; i++){
			if(storeAddr.Equals(connections[i])){
				std::cout << "Client["<<i<<"]: "<<buffer<<std::endl;
				clientexist = true;
			}
		}
		if(!clientexist){
			connections[Counter] = storeAddr;
			std::cout<<"New Client: "<<Counter<<std::endl;
			std::cout << "Client["<<Counter<<"]: "<< buffer << std::endl;
			Counter++;
		}
	}

	winSockDll.Cleanup();
	return 0;
}
开发者ID:stijncr,项目名称:PixelDelirium,代码行数:36,代码来源:Server.cpp

示例4: _UdpSocket_Bind

value _UdpSocket_Bind(value a, value b) {
	UdpSocket* s = (UdpSocket*) val_data(a);
	return alloc_bool(s->Bind(val_int(b)));
}
开发者ID:datee,项目名称:hxudp,代码行数:4,代码来源:api.cpp


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