Socket 地址:
TSharedRef<FInternetAddr> internetAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr(); bool bIsValid = true; internetAddr->SetIp(*serverIp, bIsValid); internetAddr->SetPort(serverPort);
socket tcp连接
connect send closeConnect
mySocket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(EName(NAME_Stream), "TCP Server"); if (mySocket->Connect(internetAddr.Get()))
udp协议下
sendTo(address,data)
udpSocket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(EName(NAME_DGram), "UDP Client"); udpSocket->SendTo(buffer, 4, bytesSend, internetAddr.Get());
接收
int32 recvProgress; uint8 recvBuffer[BUFFER_SIZE]; mySocket->Recv(recvBuffer, sizeof(uint8) * msgLen, recvProgress, ESocketReceiveFlags::None); ESocketReceiveFlags::Peek
标志和windows socket有很多通用的地方: 如waitall peek none
udp socket 接收方需要绑定ip 发送方不需要。
waitall 不能用在datagram 也就是UDP上 可参考MSDN。UE文档关于waitall的备注也有写。