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


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

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


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

示例1: Main

	void UdpReceiveThread::Main() {
		SocketThreadOperation *op = mSocketThreadOperation;
		UdpSocket *s = (UdpSocket*)op->mSocket;
		ErrorType error;
		StopWatch sw;
		sw.Start();
		while (!ShouldEnd()) {
			error = s->Receive(op->mIPAddress, &op->mByteStream,
				Math::ClampLong(op->mTimeoutMS - sw.GetElapsedMilliseconds(),
					0L, 16L));
			if (0L == op->mTimeoutMS ||
				(error && kErrorTimedOut != error) ||
				(0L < op->mTimeoutMS &&
				sw.GetElapsedMilliseconds() >= op->mTimeoutMS))
			{
				if (error)
					Error::Throw(error, String("[%s(%p, %p)]",
						FastFunctionName, this, op));
				s->OnReceive(op->mID, op->mIPAddress, op->mByteStream, error);
				op->mByteStream.Clear();
				sw.Reset();
				sw.Start();
				continue;
			}
		}
	}
开发者ID:JSandrew4,项目名称:FastGdk,代码行数:26,代码来源:Network.cpp

示例2: 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

示例3: _UdpSocket_Receive

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


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