The goal was to create a VFP application for receiving UDP packet from a client and responding to the same client using the IP address and the port obtained from the initial packet. The sockaddr structure that the recvfrom call populates contains required information.
The UdpBase class uses several Winsock API functions. It implements the basic functionality such as creates a UDP socket and binds it to a local port. After that the class can use this socket for sending and receiving datagrams.
The WaitForRequest method of the class indefinitely waits for incoming datagrams. Upon receiving a datagram it sends a message back to the client.
DEFINE CLASS UdpServer As UdpBase
IF NOT THIS.StartServer(nPort)
? "Waiting for incoming requests on " +;
THIS.LocalIP + ":" +;
TRANSFORM(THIS.LocalPort) + "..."
* waits indefinitely for a request from a client
* on local ip address and port specified in nPort
IF EMPTY(THIS.SenderIP) OR EMPTY(THIS.SenderPort)
* failed to get a response or
* when defining the source of the response
* displays request received
? "Request received from " + THIS.SenderIP +;
":" + TRANSFORM(THIS.SenderPort)
* assemble a data to be sent back to client
cConfirmation = "Responder: " + SYS(0) +;
" " + TTOC(DATETIME())
* sends data back to client
* the client is supposed to be in listening mode
The User Datagram Protocol (UDP) is one of the core Internet protocols. By using the UDP an application can send short messages, also known as datagrams, across the network.
A datagram is a self-contained connectionless packet, one which contains enough information in the header to allow the network to forward it to the destination independently of previous or future datagrams.
Credits: PHP (4.4.9), an HTML-embedded scripting language,
MySQL (5.1.55-log), the Open Source standard SQL database,
Version 4, freeware HTML Editor of choice. Hosted by Korax Online Inc.