Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Using the CreateFile
Converting a hexadecimal string to an integer
How to assemble an array of strings and pass it to external function
Pocket PC: custom RAPI class for operating with the System Registry
System and Local Time values
The original LoadPicture() function in VFP returns valid handles to bitmaps, icons, cursors, and metafiles
A class that encrypts and decrypts files using Cryptography API Functions
How to block the ALT+TAB shortcut (WinXP)
How to enumerate sessions and processes on a specified terminal server
How to generate GUID values
How to hot-track menu item selection in top-level form (requires VFP9)
How to retrieve version information for the specified file
Retrieving size of a remote file
Using the GradientFill function
Enumerating network resources
Pocket PC: custom RAPI class for operating with the Object Store Databases
Validating the heap of the calling process
Converting twips to pixels and vice versa
How to view icons stored in executable files (Icon Viewer) - II
Monitoring changes occurring within a directory
Uploading file to the FTP server using InternetWriteFile
Using Change Notification Objects to monitor changes to the printer or print server
Accessing examples contained in this reference through Web Services
Adding supplementary data to AVI files
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: 106  
    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 (67.202.9.192)
    7 sec.Function: 'sndPlaySound'
    25.7 min.Example: 'Displaying icons in the system tray (VFP9)'
    40.63 min.Example: 'Printing text with the Escape function'
    40.68 min.Function: 'GetDlgItem'
    Function group: 'Dialog Box'
    1.62 hrs.Example: 'Starting an external application in VFP using WinExec'
     
    Function group: 'Brush'
    2.07 hrs.Function: 'ChangeClipboardChain'
    Function group: 'Clipboard'
     Function: 'GdiFlush'
    Function group: 'Painting and Drawing'
    5.54 hrs.Example: 'Using shared memory to exchange data between two FoxPro applications'
     Function: 'IsNetworkAlive'
    Function group: 'System Information'
    Google
    Advertise here!