当前位置: 首页>>代码示例>>C++>>正文


C++ UDPClose函数代码示例

本文整理汇总了C++中UDPClose函数的典型用法代码示例。如果您正苦于以下问题:C++ UDPClose函数的具体用法?C++ UDPClose怎么用?C++ UDPClose使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了UDPClose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: UDPPerformanceTask

/*****************************************************************************
  Function:
	void UDPPerformanceTask(void)

  Summary:
	Tests the transmit performance of the UDP module.

  Description:
	This function tests the transmit performance of the UDP module.  At boot,
	this module will transmit 1024 large UDP broadcast packets of 1024 bytes
	each.  Using a packet sniffer, one can determine how long this process 
	takes and calculate the transmit rate of the stack.  This function tests 
	true UDP performance in that it will open a socket, transmit one packet, 
	and close the socket for each loop.  After this initial transmission, the
	module can be re-enabled by holding button 3.
	
	This function is particularly useful after development to determine the
	impact of your application code on the stack's performance.  A before and
	after comparison will indicate if your application is unacceptably
	blocking the processor or taking too long to execute.

  Precondition:
	UDP is initialized.

  Parameters:
	None

  Returns:
	None
  ***************************************************************************/
void UDPPerformanceTask(void)
{
	UDP_SOCKET	MySocket;
	NODE_INFO	Remote;
	WORD		wTemp;
	static DWORD dwCounter = 1;

	if((BUTTON3_IO) && (dwCounter > 1024))
		return;

	// Suppress transmissions if we don't have an Ethernet link so our counter starts correctly at 0x00000001
	if(!MACIsLinked())
		return;
	
	// Set the socket's destination to be a broadcast over our IP 
	// subnet
	// Set the MAC destination to be a broadcast
	memset(&Remote, 0xFF, sizeof(Remote));
	
	// Open a UDP socket for outbound transmission
	MySocket = UDPOpen(0, &Remote, PERFORMANCE_PORT);
	
	// Abort operation if no UDP sockets are available
	// If this ever happens, incrementing MAX_UDP_SOCKETS in 
	// StackTsk.h may help (at the expense of more global memory 
	// resources).
	if(MySocket == INVALID_UDP_SOCKET)
		return;
	
	// Make certain the socket can be written to
	if(!UDPIsPutReady(MySocket))
	{
		UDPClose(MySocket);
		return;
	}
	
	// Put counter value into first 4 bytes of the packet
	UDPPutArray((BYTE*)&dwCounter, sizeof(dwCounter));
	dwCounter++;
	
	wTemp = UDPPutROMArray((ROM BYTE*)
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 256 bytes.\r\n"
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 256 bytes.\r\n"
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 256 bytes.\r\n"
			"The quick brown fox tried to jump over the yellow dog.  Unfortunately, the yellow dog stood up while the fox was in mid-jump.  As a result, the two collided.  Then, the dog, being the omnivore that it is, ate the quick brown fox.  This line is 252b. \r\n", 1020);

	// Send the packet
	UDPFlush();
	
	// Close the socket so it can be used by other modules
	UDPClose(MySocket);
}
开发者ID:gaopindianzi,项目名称:plcethpic97j60,代码行数:82,代码来源:UDPPerformanceTest.c

示例2: DHCPInit

/*****************************************************************************
  Function:
	void DHCPInit(BYTE vInterface)

  Summary:
	Resets the DHCP client module for the specified interface.

  Description:
	Resets the DHCP client module, giving up any current lease, knowledge of 
	DHCP servers, etc. for the specified interface.

  Precondition:
	None

  Parameters:
	vInterface - Interface number to initialize DHCP client state variables 
		for.   If you only have one interface, specify 0x00.

  Returns:
	None

  Remarks:
	This function may be called multiple times throughout the life of the 
	application, if desired.  
***************************************************************************/
void DHCPInit(BYTE vInterface)
{
	BYTE i;
	
    // initialize global module statics
    // DHCPClientInitializedOnce = FALSE;

	// Upon the first call after POR, we must reset all handles to invalid so 
	// that we don't inadvertently close someone else's handle.
	if(!DHCPClientInitializedOnce)
	{
		DHCPClientInitializedOnce = TRUE;
		for(i = 0; i < NETWORK_INTERFACES; i++)
		{
			LoadState(i);
			DHCPClient.hDHCPSocket = INVALID_UDP_SOCKET;
		}		
	}
	
	
	LoadState(vInterface);
	
	if(DHCPClient.hDHCPSocket != INVALID_UDP_SOCKET)
	{
		UDPClose(DHCPClient.hDHCPSocket);
		DHCPClient.hDHCPSocket = INVALID_UDP_SOCKET;
	}

	// Reset state machine and flags to default values
	DHCPClient.smState = SM_DHCP_GET_SOCKET;
	DHCPClient.flags.val = 0;
	DHCPClient.flags.bits.bUseUnicastMode = TRUE;	// This flag toggles before use, so this statement actually means to start out using broadcast mode.
	DHCPClient.flags.bits.bEvent = TRUE;
}
开发者ID:alaneve,项目名称:SeniorDesign,代码行数:59,代码来源:DHCP.c

示例3: loopback_udp

void loopback_udp(uint8 ch, uint16 port)
{
    int ret;
    uint32 destip = 0;
    uint16 destport;

    ret = UDPRecv(ch, data_buf, TX_RX_MAX_BUF_SIZE, (uint8*)&destip, &destport);

    if(ret > 0) {				// Received
        ret = UDPSend(ch, data_buf, ret, (uint8*)&destip ,destport);

        if(ret == ERROR_TIME_OUT) {
            ERR("Timeout");
            UDPClose(ch);
            DBG("UDP Socket Close");
        }

    } else if(ret == ERROR_NOT_UDP_SOCKET) {	// Not UDP Socket, It's TCP Socket
        DBG("TCP Socket Close");
        TCPClose(ch);
    } else if(ret == ERROR_CLOSED) {		// Socket Closed
        LOGA("UDP Loop-Back Started - ch(%d)",(uint16)ch);
        UDPOpen(ch, port);
    }
}
开发者ID:ConvTeam,项目名称:ConvTest,代码行数:25,代码来源:loopback.c

示例4: cUDPGenericClose

//	Callback function
int cUDPGenericClose()
{
	UDPClose(udpSocket[callbackUdpSocket-1]);
	udpSocket[callbackUdpSocket-1] = INVALID_UDP_SOCKET;
	numUdpSocket--;
	return 0;
}
开发者ID:ElectronicsWIT,项目名称:AirFishBowl,代码行数:8,代码来源:UDPlib.c

示例5: vscp_udpinit

int8_t vscp_udpinit( void )
{
    NODE_INFO remote_node;

    remote_node.IPAddr.v[ 0 ] = 0xff;	// Broadcast
    remote_node.IPAddr.v[ 1 ] = 0xff;
    remote_node.IPAddr.v[ 2 ] = 0xff;
    remote_node.IPAddr.v[ 3 ] = 0xff;
    remote_node.MACAddr.v[ 0 ] = 0xff;
    remote_node.MACAddr.v[ 1 ] = 0xff;
    remote_node.MACAddr.v[ 2 ] = 0xff;
    remote_node.MACAddr.v[ 3 ] = 0xff;
    remote_node.MACAddr.v[ 4 ] = 0xff;
    remote_node.MACAddr.v[ 5 ] = 0xff;

    // setup receive socket
    vscp_udp_receivesocket = UDPOpen( VSCP_LEVEL2_UDP_PORT, &remote_node, NULL );
    if ( INVALID_SOCKET == vscp_udp_receivesocket ) return FALSE;

    // Setup transmit socket
    vscp_udp_transmitsocket = UDPOpen( 30200, &remote_node, VSCP_LEVEL2_UDP_PORT );
    if ( INVALID_SOCKET == vscp_udp_transmitsocket ) {
        UDPClose( vscp_udp_receivesocket );
        return FALSE;
    }
}
开发者ID:jaej-dev,项目名称:vscp_firmware,代码行数:26,代码来源:vscp_udp.c

示例6: closesocket

/*****************************************************************************
  Function:
	int closesocket( SOCKET s )
	
  Summary:
	The closesocket function closes an existing socket.

  Description:
	The closesocket function closes an existing socket.  
    This function releases the socket descriptor s.  
    Further references to s fails with SOCKET_ERROR code.  
    Any data buffered at the socket is discarded.  If the 
    socket s is no longer needed, closesocket() must be 
    called in order to release all resources associated with s.

  Precondition:
	None.

  Parameters:
	s - Socket descriptor returned from a previous call to socket

  Returns:
	If closesocket is successful, a value of 0 is returned. 
    A return value of SOCKET_ERROR (-1) indicates an error.

  Remarks:
	None.
  ***************************************************************************/
int closesocket( SOCKET s )
{
    struct BSDSocket *socket;
    
    if( s >= BSD_SOCKET_COUNT )
        return SOCKET_ERROR;

    socket = &BSDSocketArray[s];

    if( socket->SocketType == SOCK_STREAM)
    {
        TCPDisconnect(socket->SocketID);
    }
    else //udp sockets
    {
        UDPClose(socket->SocketID);
    }

    if(socket->isServer == TRUE)
    {
        socket->bsdState = SKT_LISTEN;
    }
    else
    {
        socket->SocketType = SOCK_DGRAM;
        socket->bsdState   = SKT_CLOSED;
        socket->SocketID   = INVALID_SOCKET;
    }
    return 0; //success
}
开发者ID:ezequieldonhauser,项目名称:PIC18F66J60,代码行数:58,代码来源:BerkeleyAPI.c

示例7: NBNSDeInit

/*********************************************************************
 * Function:        void NBNSDeInit(const TCPIP_STACK_MODULE_CTRL* const stackCtrl)
 *
 * PreCondition:    None
 *
 * Input:           stackCtrl - Interface and stack module data.
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        DeInitializes state machine
 *
 * Note:            None
 ********************************************************************/
void NBNSDeInit(const TCPIP_STACK_MODULE_CTRL* const stackCtrl)
{
    // if(stackCtrl->stackAction == TCPIP_STACK_ACTION_DEINIT) // stack shut down
    // if(stackCtrl->stackAction == TCPIP_STACK_ACTION_IF_DOWN) // interface down

    // one way or another this interface is going down

    if(stackCtrl->stackAction == TCPIP_STACK_ACTION_DEINIT)
    {   // whole stack is going down
        if(nbnsInitCount > 0)
        {   // we're up and running
            if(--nbnsInitCount == 0)
            {   // all closed
                // release resources
                if(nbnsDcpt.uSkt != INVALID_UDP_SOCKET)
                {
                   UDPClose(nbnsDcpt.uSkt);
                   nbnsDcpt.uSkt = INVALID_UDP_SOCKET;
                }
                nbnsDcpt.sm = NBNS_HOME;
            }
        }
    }

}
开发者ID:dakkanner,项目名称:cst-417-lab,代码行数:40,代码来源:nbns.c

示例8: ChipKITUDPBegin

/****************************************************************************
  Function:
   UDP_SOCKET ChipKITUDPBegin(UDP_PORT localPort)

  Description:
    Implementes the Arduino UDP begin function.
 
  Parameters:
    localPort   - The port to start listening on.

  Returns:
    The socket that was opened, or INVALID_UDP_SOCKET if it couldn't get one

  Remarks:
    Creates a socket and starts listening on the specifed port.
    Note that Arduino never specifies an IP address with this, that
    is done on the individual send packetes.
    If there is not enough space for the socket cache, this API will fail
   
  ***************************************************************************/
UDP_SOCKET ChipKITUDPBegin(UDP_PORT localPort)
{
	UDP_SOCKET hUDP = INVALID_UDP_SOCKET;
    hUDP = UDPOpen(localPort, NULL, 0);

	if(hUDP < MAX_UDP_SOCKETS && rgUDPSocketBuffers[hUDP] == NULL)
	{
		rgUDPSocketBuffers[hUDP] = (UDPSB *) malloc(sizeof(UDPSB));	
		if(rgUDPSocketBuffers[hUDP] != NULL)
		{
			memset(rgUDPSocketBuffers[hUDP], 0, sizeof(sizeof(UDPSB)));
		}

		// no space for the buffer, no socket!
		else
		{
			UDPClose(hUDP);
			hUDP = INVALID_UDP_SOCKET;
		}
	}

    ChipKITPeriodicTasks();

    return(hUDP);
}
开发者ID:nsfw,项目名称:kelp,代码行数:45,代码来源:chipKITEthernetAPI.c

示例9: closesocket

/*****************************************************************************
  Function:
	int closesocket( SOCKET s )

  Summary:
	The closesocket function closes an existing socket.

  Description:
	The closesocket function closes an existing socket.
	This function releases the socket descriptor s.
	Any data buffered at the socket is discarded.  If the
	socket s is no longer needed, closesocket() must be
	called in order to release all resources associated with s.

  Precondition:
	None.

  Parameters:
	s - Socket descriptor returned from a previous call to socket

  Returns:
	If closesocket is successful, a value of 0 is returned.
	A return value of SOCKET_ERROR (-1) indicates an error.

  Remarks:
	None.
  ***************************************************************************/
int closesocket( SOCKET s )
{
    struct BSDSocket *socket;

    if( s >= BSD_SOCKET_COUNT )
        return SOCKET_ERROR;

    socket = &BSDSocketArray[s];

    if(socket->bsdState == SKT_CLOSED)
        return 0;	// Nothing to do, so return success

    if( socket->SocketType == SOCK_STREAM)
    {
        if(socket->bsdState >= SKT_LISTEN)
        {
            HandlePossibleTCPDisconnection(s);

            if(socket->bsdState == SKT_LISTEN)
                return 0;
        }
    }
    else //udp sockets
    {
        if(socket->SocketID != INVALID_UDP_SOCKET)
            UDPClose(socket->SocketID);
    }

    socket->bsdState = SKT_CLOSED;
    return 0; //success
}
开发者ID:bend,项目名称:PIC,代码行数:58,代码来源:BerkeleyAPI.c

示例10: UDPInit

/*********************************************************************
 * Function:        void UDPInit(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Initializes internal variables.
 *
 * Note:
 ********************************************************************/
void        UDPInit(void)
{
    UDP_SOCKET s;

    for ( s = 0; s < MAX_UDP_SOCKETS; s++ )
    {
      UDPClose(s);
    }
}
开发者ID:polilies,项目名称:modbus_tcp_server_project,代码行数:24,代码来源:udp.c

示例11: DHCPDisable

/*****************************************************************************
 Function:
 void DHCPDisable(BYTE vInterface)

 Summary:
 Disables the DHCP Client for the specified interface.

 Description:
 Disables the DHCP client for the specified interface by sending the state
 machine to "SM_DHCP_DISABLED".  If the interface was previously configured
 by DHCP, the configuration will continue to be used but the module will no
 longer preform any renewals.

 Precondition:
 None

 Parameters:
 vInterface - Interface number to disable the DHCP client on.   If you only
 have one interface, specify 0x00.

 Returns:
 None

 Remarks:
 Since the interface continues using its old configuration, it is possible
 that the lease may expire and the DHCP server provide the IP to another
 client.  The application should replace the current IP address and other
 configuration with static information following a call to this function.
 ***************************************************************************/
void DHCPDisable(BYTE vInterface) {
	LoadState(vInterface);

	if (DHCPClient.hDHCPSocket != INVALID_UDP_SOCKET) {
		UDPClose(DHCPClient.hDHCPSocket);
		DHCPClient.hDHCPSocket = INVALID_UDP_SOCKET;
	}

	DHCPClient.smState = SM_DHCP_DISABLED;
}
开发者ID:kekovski,项目名称:MSP430,代码行数:39,代码来源:DHCP.c

示例12: UDPInit

/*****************************************************************************
  Function:
	void UDPInit(void)

  Summary:
	Initializes the UDP module.

  Description:
	Initializes the UDP module.  This function initializes all the UDP 
	sockets to the closed state.

  Precondition:
	None

  Parameters:
	None

  Returns:
  	None
  	
  Remarks:
	This function is called only one during lifetime of the application.
  ***************************************************************************/
void UDPInit(void)
{
    UDP_SOCKET s;

    for ( s = 0; s < MAX_UDP_SOCKETS; s++ )
    {
		UDPClose(s);
    }
	Flags.bWasDiscarded = 1;
}
开发者ID:KiwiJaune,项目名称:RecMiwiPi,代码行数:33,代码来源:UDP.c

示例13: DHCPServer_Disable

void DHCPServer_Disable(void)
{
	smDHCPServer = DHCPS_DISABLE;

	if(MySocket != INVALID_UDP_SOCKET)
	{
		UDPClose(MySocket);
		MySocket = INVALID_UDP_SOCKET;
	}
}
开发者ID:DIYzzuzpb,项目名称:contiki-mplabx,代码行数:10,代码来源:DHCPs.c

示例14: UDPCloseAllSockets

void UDPCloseAllSockets(void)
{
    UDPSOCKET * pSocket = NULL;

    // go until you empty the list.
    while((pSocket = FFNext(&g_ffptListeningUDPSockets, NULL)) != NULL)
    {
        UDPClose(pSocket);
    }
}
开发者ID:757Nauman,项目名称:chipKIT32-MAX,代码行数:10,代码来源:UDP.c

示例15: AnnounceIP

/****************************************************************************************************
  Function:
            void AnnounceIP(void)
    
  Summary:
    Transmits an Announce packet.
  Conditions:
    Stack is initialized()
  Return:
    None
  Side Effects:
    None
  Description:
    AnnounceIP opens a UDP socket and transmits a broadcast packet to port
    \30303. If a computer is on the same subnet and a utility is looking
    for packets on the UDP port, it will receive the broadcast. For this
    application, it is used to announce the change of this board's IP
    address. The messages can be viewed with the TCP/IP Discoverer
    software tool.
  Remarks:
    A UDP socket must be available before this function is called. It is
    freed at the end of the function. MAX_UDP_SOCKETS may need to be
    increased if other modules use UDP sockets.                                                      
  ****************************************************************************************************/
void AnnounceIP(void)
{
	UDP_SOCKET	MySocket;
	BYTE 		i;

	if(!MACIsLinked())  // Check for link before blindly opening and transmitting (similar to DHCP case)
		return;

	// Open a UDP socket for outbound broadcast transmission
	//MySocket = UDPOpen(2860, NULL, ANNOUNCE_PORT);
	MySocket = UDPOpenEx(0,UDP_OPEN_SERVER,2860, ANNOUNCE_PORT);
            LED1_IO = 0;

	// Abort operation if no UDP sockets are available
	// If this ever happens, incrementing MAX_UDP_SOCKETS in 
	// StackTsk.h may help (at the expense of more global memory 
	// resources).
	if(MySocket == INVALID_UDP_SOCKET)
		return;
	
	// Make certain the socket can be written to
	while(!UDPIsPutReady(MySocket));
	
	// Begin sending our MAC address in human readable form.
	// The MAC address theoretically could be obtained from the 
	// packet header when the computer receives our UDP packet, 
	// however, in practice, the OS will abstract away the useful
	// information and it would be difficult to obtain.  It also 
	// would be lost if this broadcast packet were forwarded by a
	// router to a different portion of the network (note that 
	// broadcasts are normally not forwarded by routers).
	UDPPutArray((BYTE*)AppConfig.NetBIOSName, sizeof(AppConfig.NetBIOSName)-1);
	UDPPut('\r');
	UDPPut('\n');

	// Convert the MAC address bytes to hex (text) and then send it
	i = 0;
	while(1)
	{
		UDPPut(btohexa_high(AppConfig.MyMACAddr.v[i]));
	    UDPPut(btohexa_low(AppConfig.MyMACAddr.v[i]));
	    if(++i == 6u)
	    	break;
	    UDPPut('-');
	}

	// Send some other human readable information.
	UDPPutROMString((ROM BYTE*)"\r\nDHCP/Power event occurred");

	// Send the packet
	UDPFlush();
	
	// Close the socket so it can be used by other modules
	UDPClose(MySocket);
}
开发者ID:xd009642,项目名称:Embedded_rover_code,代码行数:79,代码来源:Announce.c


注:本文中的UDPClose函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。