• ue4 socket


    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的备注也有写。

  • 相关阅读:
    12.1
    11.26
    12.5Java日报
    11.25
    11.27
    12.03
    11.28
    12.04
    如何在TortoiseGit中使用sshkeygen生成的key
    leetcode 39 组合总和
  • 原文地址:https://www.cnblogs.com/mattins/p/5703460.html
Copyright © 2020-2023  润新知