| Home Page | Recent Changes

UdpLink

An Internet UDP connectionless socket.

Properties

const int BroadcastAddr

Methods

(The IpAddr struct is declared in the InternetLink class.)

Native functions

native function int BindPort (optional int Port, optional bool bUseNextAvailable)
Binds a free port or optional port specified in argument one.
native function bool SendText (IpAddr Addr, coerce string Str)
Sends text string. Appends a CR/LF if LinkMode=MODE_Line.
native function bool SendBinary (IpAddr Addr, int Count, byte B[255])
Send data as a byte array.
native function int ReadText (out IpAddr Addr, out string Str)
Reads text string. Returns number of bytes read.
native function int ReadBinary (out IpAddr Addr, int Count, out byte B[255])
Read data as a byte array.

Events

Note that ReceivedBinary is only called once per frame which will tie the amount of data you can read to the frame rate. In cases where your receiving several kilobytes you can manually receive pending data within a loop in Tick. However while reading this data the rest of the game will be stopped until you're done.

ReceivedText and ReceivedLine are also called once per frame, but should not require this technique as they get as much data as possible.

event ReceivedText (IpAddr Addr, string Text)
Called when data is received and connection mode is MODE_Text.
event ReceivedLine (IpAddr Addr, string Line)
Called when data is received and connection mode is MODE_Line.
event ReceivedBinary (IpAddr Addr, int Count, byte B[255])
Called when data is received and connection mode is MODE_Binary.

[BWF]GrimReaper: SendBinary seems to be broken. Only 255byte packets can be sent. No way to add multiple 255 byte arrays into 1 packet.

El Muerte TDS: what do you mean broken? it's a static array of size 255, so ofcourse you can only send packets with a max of 255 bytes. But does it matter that you can only send 255 bytes at the time (instead of the absolute ~1200 bytes UDP allows) ?

[BWF]GrimReaper: Yes it does matter i won't disclose what i intended to do with it. Received packets are broken up into 255byte blocks. However sending multiple 255byte blocks isn't possible. IMO this is broken since it should work the same both ways.

El Muerte TDS: well sorry but I can't reproduce anything broken, the code below works:

class test extends UdpLink;

event prebeginplay()
{
    local UdpLink.ipaddr dest;
    local byte data[255];
    local int i, j;

    BindPort(9001, true);
    StringToIpAddr("192.168.1.1", dest);
    dest.port = 9000;
    
    for (j = 0; j < 10; j++)
    {
        data[0] = 48+j;
        for (i = 1; i < 255; i++)
        {
            if (i % 10 == 0) data[i] = 48+j;
                else data[i] = 46;
        }
        data[254] = 10;
        SendBinary(dest, 255, data);
    }
}

GRAF1K: Still trying to use vBCode after that daylight savings time post on BeyondUnreal, El Muerte? ;)

El Muerte TDS: bleh, forgot what the right tag was, haven't posted any unrealscript on the wiki quite some time.

[BWF]GrimReaper: Didn't get round to testing the above code but it doesn't send it out in one packet does it?!? The problem i'm stuck with is telling uscript the difference between send me 4x256byte packets or a (4x256)=1024byte packet aka packet defragmentization :).

El Muerte TDS: udp output isn't buffered, so it's count size send per package (so a max of 256 bytes per packet). But does it matter that much?

Foxpaw: Maybe it's just my imagination, but doesn't UDP not have the concept of packets? I thought it was a completely unformatted, un-error checked stream of data?

El Muerte TDS: the only thing diffirent is that no connection is established. Data send via UDP is still inside a IP packet, so it does have packets.

[BWF]GrimReaper: I tried to write my MD5 bypass proxy in uscript as a challenge. This was te only thing stopping me so i might aswell say it's broken :p. And yes UDP is connectionless and does send in packets. Main difference with TCP is is has no form of flow control and and doesn't guarantee packets to be in-order or reliable.

DemonThing: UDP is connectionless and uses packets (datagrams), hence the name User Datagram Protocol. TCP is connection-oriented and uses a stream. Therefore, in UDP, packet size does matter, while in TCP it does not.

Samples

UDP server sample

Known subclasses

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In