Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Simple Window Viewer
Extended MessageBox Class
How to enable the SE_SHUTDOWN_NAME privilege for the application
Retrieving configuration information for the specified server (Win2000/XP)
Shortcut Menu Class
Testing Clipboard functions: emptying the clipboard
Testing serial ports
Hiding mouse cursor
How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory
How to obtain Content-Type value for a file type from the System Registry
Drawing cursors for the classes defined by the system (preregistered): BUTTON, EDIT, LISTBOX etc.
How to extract frames from AVI files
How to generate GUID values
OS version and revision
Retrieving configuration information for the specified workstation (Win2000/XP)
Retrieving Network Provider information
Switching between keyboard layouts
Disabling drawing in the VFP form
Enumerating devices installed on the local machine
Enumerating files opened on the network
Enumerating ports that are available for printing on a specified server
GDI+: Creating thumbnails to preview images in a directory
GDI+: printing image file
GetFocus returns a HWND value
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: 74  
    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 (184.72.91.94)
    1.06 hrs.Function: 'PageSetupDlg'
    Function group: 'Common Dialog Box'
     Example: 'Setting the Window Region for a form'
     Function: 'GetClassName'
    9.75 hrs.Function: 'GetBkMode'
    Function group: 'Painting and Drawing'
     Function: 'CommandLineToArgvW'
    Function group: 'Process and Thread'
    12.81 hrs.Example: 'Establishing connection using the SQLDriverConnect'
     Example: 'Storing the environment strings in cursor'
    12.82 hrs.Function: 'SizeofResource'
    Function group: 'Resource'
    13.05 hrs.Function: 'SHGetPathFromIDList'
    Function group: 'Shell Functions'
     Function: 'RegEnumKey'
    Google
    Advertise here!