Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to draw custom Window Caption on FoxPro form
Printf-style formatted text output in VFP
Using Month Calendar Control (VFP9, Comctl32.dll)
How to enumerate cookies and URL History entries in the cache of the local computer
How to retrieve number of objects in the Recycle Bin
Reading list of folders and files on FTP server
Reading the state of mouse buttons within DO WHILE loop
Converting image file to .ICO file
Placing On-screen Alert on top of all windows
Pocket PC: custom RAPI class for operating with files and folders on mobile device
Adding and deleting User Accounts
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)
How to detect if additional monitor is connected and active
How to print FoxPro form
Disabling mouse and keyboard input for the main VFP window (with the app still running)
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
How to adjust monitor brightness (Vista, monitor with DDC support)
Switching between keyboard layouts
Retrieving country-specific dialing information from the Windows Telephony list of countries
Winsock: connecting to a news server (NNTP, port 119)
How to upload a local file to FTP server using FtpPutFile
Locking and unlocking file of a VFP table
Programmatically removing submenus from VFP main menu
Starting a dialog box for connecting to network resources (mapping network drive)
How to build UDP responder

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
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

PROCEDURE WaitForRequest(nPort)
        IF NOT THIS.StartServer(nPort)
                RETURN .F.
        ELSE
                ? "Waiting for incoming requests on " +;
                        THIS.LocalIP + ":" +;
                        TRANSFORM(THIS.LocalPort) + "..."
        ENDIF
        
        * waits indefinitely for a request from a client
        * on local ip address and port specified in nPort
        THIS.ReceiveDatagram

        IF EMPTY(THIS.SenderIP) OR EMPTY(THIS.SenderPort)
        * failed to get a response or
        * when defining the source of the response
                RETURN .F.
        ELSE
        * displays request received
                ? "Request received from " + THIS.SenderIP +;
                        ":" + TRANSFORM(THIS.SenderPort)
                ? THIS.DataReceived
        ENDIF
        
        * assemble a data to be sent back to client
        LOCAL cConfirmation
        cConfirmation = "Responder: " + SYS(0) +;
                " " + TTOC(DATETIME())
        
        * sends data back to client
        * the client is supposed to be in listening mode
        THIS.SendDatagram(m.cConfirmation,;
                THIS.SenderIP, THIS.SenderPort)
        
ENDDEFINE

See also:
  • How to create non-blocking Winsock server
  •  
      Members area. Log in to view this example.
     
      User name:
      Password:
     
     
      Forgot your password?
     
      Sign up for
    the Membership
     
     


    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    8013 bytes  
    Created: 2001-07-19 12:00:00  
    Modified: 2009-03-16 13:55:49  
    Visits in 7 days: 77  
    Listed functions:
    bind
    closesocket
    gethostbyname
    gethostname
    htons
    inet_addr
    inet_ntoa
    recvfrom
    sendto
    socket
    WSACleanup
    WSAGetLastError
    WSAStartup
    Printer friendly API declarations
    My comment:
    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.
    Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    There are no notes on this subject.


    Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (23.22.76.170)
    5 sec.Example: 'How to enumerate sessions and processes on a specified terminal server'
    1.74 hrs.Function: 'VirtualAllocEx'
     Example: 'Creating a clipping region from the path selected into the device context of a form'
     Example: 'Copying files as a transacted operation (Vista)'
    13.97 hrs.Function: 'DrawDibDraw'
     Function: 'WSACloseEvent'
    Function group: 'Windows Sockets 2 (Winsock)'
    14.64 hrs.Function: 'IsIconic'
    16.53 hrs.Function: 'JetCloseTable'
    Function group: 'Extensible Storage Engine (ESE, Jet Blue)'
    18.26 hrs.Function: 'waveInGetDevCaps'
     Example: 'Using File Mapping for enumerating files opened by Visual FoxPro'
    Google
    Advertise here!