Ejemplo n.º 1
0
void UDPSocket::sendPacket(const UDPAddr &target, Util::MemoryFrame data)
{
  int success = ::sendto(_s, (char*)data.begin(), data.size(), NULL, (sockaddr*)&target, sizeof(sockaddr_in));
  if(success == SOCKET_ERROR)
  {
    throw GeneralException("::send failed");
  }
}
Ejemplo n.º 2
0
  void passPacket(const SOCKADDR& sender, Util::MemoryFrame packet)
  {
    INTERLOCKED;
    GamePacket gamePacket;
    memcpy(gamePacket.data, packet.begin(), packet.size());
    gamePacket.packetSize = packet.size();
    gamePacket.sender = sender;
    gamePacket.timeStamp = GetTickCount();

    incomingGamePackets.push(gamePacket);

    SetEvent(receiveEvent);
  }
Ejemplo n.º 3
0
Util::MemoryFrame UDPSocket::receivePacket(UDPAddr &target, Util::MemoryFrame dest)
{
  //int targetSize = sizeof(target);
  _state = 0;
  int fromlen = sizeof(sockaddr);
  int byteCount = ::recvfrom(_s, (char*)dest.begin(), dest.size(), NULL, (sockaddr*)&target, &fromlen);
  if(byteCount == SOCKET_ERROR)
  {
    _state = WSAGetLastError();
    if( _state == WSAEWOULDBLOCK
      ||_state == WSAECONNRESET)
      return Util::MemoryFrame();
    throw GeneralException("::recv failed");
  }
  return dest.getSubFrame(0, byteCount);
}