示例#1
0
void FUdpMessageBeacon::SendSegment(EUdpMessageSegments::Type SegmentType)
{
	FUdpMessageSegment::FHeader Header;

	Header.SenderNodeId = NodeId;
	Header.ProtocolVersion = UDP_MESSAGING_TRANSPORT_PROTOCOL_VERSION;
	Header.SegmentType = SegmentType;

	FArrayWriter Writer;
	
	Writer << Header;
	Writer << NodeId;

	int32 Sent;

	Socket->Wait(ESocketWaitConditions::WaitForWrite, BeaconInterval);
	Socket->SendTo(Writer.GetData(), Writer.Num(), Sent, *MulticastAddress);
}
示例#2
0
void FUdpMessageProcessor::AcknowledgeReceipt( int32 MessageId, const FNodeInfo& NodeInfo )
{
	FUdpMessageSegment::FHeader Header;

	Header.RecipientNodeId = NodeInfo.NodeId;
	Header.SenderNodeId = LocalNodeId;
	Header.ProtocolVersion = UDP_MESSAGING_TRANSPORT_PROTOCOL_VERSION;
	Header.SegmentType = EUdpMessageSegments::Acknowledge;

	FUdpMessageSegment::FAcknowledgeChunk AcknowledgeChunk;

	AcknowledgeChunk.MessageId = MessageId;

	FArrayWriter Writer;

	Writer << Header;
	Writer << AcknowledgeChunk;

	int32 Sent;

	Socket->SendTo(Writer.GetData(), Writer.Num(), Sent, *NodeInfo.Endpoint.ToInternetAddr());
}
bool FTcpMessageTransportConnection::SendMessages()
{
	if (Outbox.IsEmpty() && bSentHeader)
	{
		return true;
	}

	if (!Socket->Wait(ESocketWaitConditions::WaitForWrite, FTimespan::Zero()))
	{
		return true;
	}

	if (!bSentHeader)
	{
		FArrayWriter HeaderData;
		FTcpMessageHeader MessageHeader(LocalNodeId);
		HeaderData << MessageHeader;

		if (!BlockingSend(HeaderData.GetData(), sizeof(FTcpMessageHeader)))
		{
			return false;
		}

		bSentHeader = true;
		TotalBytesSent += sizeof(FTcpMessageHeader);
	}
	else
	{
		FTcpSerializedMessagePtr Message;
		while (Outbox.Dequeue(Message))
		{
			int32 BytesSent = 0;
			const TArray<uint8>& Payload = Message->GetDataArray();

			// send the payload size
			FArrayWriter MessagesizeData = FArrayWriter(true);
			uint32 Messagesize = Payload.Num();
			MessagesizeData << Messagesize;

			if (!BlockingSend(MessagesizeData.GetData(), sizeof(uint32)))
			{
				return false;
			}

			TotalBytesSent += sizeof(uint32);

			// send the payload
			if (!BlockingSend(Payload.GetData(), Payload.Num()))
			{
				return false;
			}

			TotalBytesSent += Payload.Num();

			// return if the socket is no longer writable, or that was the last message
			if (Outbox.IsEmpty() || !Socket->Wait(ESocketWaitConditions::WaitForWrite, FTimespan::Zero()))
			{
				return true;
			}
		}
	}
	return true;
}