Thursday, December 02, 2004

EFTPOS sucks

When I got my WOF yesterday, they charged me twice because the first time the EFTPOS machine said it was declined, but my bank thinks it wasn't. Lame... Now I have to go back over.

Last night I finished reading The Da Vinci Code so I took to back to Aimee and got a new book. I don't remember what it is called, but I haven't started reading it yet. Instead I watched Boys Don't Cry. That is a pretty disturbing movie, but really good. I wonder if it was based on a true story.

I got an email this morning about some of the wxWindows work I did on UDP sockets a year ago. Interesting... I am glad people are using it. I sent the guy back some info answering his questions on how to use it... For the record, here is how it is done:

1. get a new IPv4 address, then set the port you want to broadcast on, then set the address using the AnyAddress method. This sets it to the address of the local machine (so the responding machine knows where to reply)

2. get another IPv4 address and set that to the same port and set the hostname to the network broadcast address, 255.255.255.255.

3. Now comes the good part. Get a new Datagram Socket using the first addr and set some options including SO_BROADCAST flag. If you don't have this flag, then it can't broadcast. I was setting the SO_REUSEADDR flag as well, but that is up to you. Set up any notifications and event handlers you want. Then using the broadcast address you set up before, SendTo.

wxIPV4address *addr = new wxIPV4address;
addr->Service(MY_PORT);
addr->AnyAddress();

wxIPV4address *otherAddr = new wxIPV4address;
otherAddr->Service(MY_PORT);
otherAddr->Hostname(0xFFFFFFFF);

m_sock = new wxDatagramSocket(*addr, wxSOCKET_NONE);
const int optval = 1;
m_sock->SetOption(SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
m_sock->SetOption(SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
m_sock->SendTo(*otherAddr, myMsg->GetMsg(), BROADCAST_MSG_LENGTH);

No comments: