UDP Packet Communication Callback

I have written an application using GLUT which displays an object in 3D space, illuminated and rendered correctly.

I would like the object to be oriented depending upon some data which will be transmitted to the routine regularly by UDP on ethernet. I have a function which will read data from the UDP port when called.

I would like to know how to reqister a callback to get the program to read data either every time a new packet arrives, or at a fixed interval.

I hope you can help

John

I assume you have two sections of code, one which monitors the UDP network and the other which renders your OpenGL object.

The UDP monitor should define a function like this:

void RegisterCallback(int (NewUDPDataFn)(BYTE NewData) );

also the UDP monitor should have a variable declared to hold the address of the callback function:

int (NewUDPData)(BYTE NewData)

When your OpenGL code calls RegisterCallback with the address of its own function for handling incoming UDP data, RegisterCallback should store the address as follows:

void RegisterCallback(int (NewUDPDataFn)(BYTE NewData) )
{
NewUDPData = NewUDPDataFn;
}

Now, whenever new UDP data appears, your UDP monitor code makes the following call:

NewUDPData((BYTE*)UDPData);

At that point the OpenGL code gets the UPD data and you are off and running.

About the only thing left is to define the data structure you will use to pass UDP Data.

Hope this helps.

Mike Metcalf

1 Like