本文整理汇总了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;
}
}
}
示例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;
}
示例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)));
}