⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp_serv.c

📁 基于vxworks操作系统的电话语音平台系统
💻 C
字号:


#include "PUB\PUB_INCL.H"
#include "PUB\PUB_defi.H"
#include "PUB\PUB__MSG.H"
#include "net_proc.h"


extern void InitServerFsm(VOID);
extern VOID NewClientHdl( int newsocket, struct sockaddr_in clientAddr );
extern STATUS channel_open_as_server( int *Socket );
extern VOID TcpipSendRecvHdl( US port_num );

BOOL NetInitComplete=FALSE;

/****************************************************************************
*
* tcpServer - accept and process requests over a TCP socket
*
* This routine creates a TCP socket, and accepts connections over the socket

* from clients. Each client connection is handled by spawning a separate
* task to handle client requests.
*
* This routine may be invoked as follows:
*       -> sp tcpServer
*       task spawned: id = 0x3a6f1c, name = t1
*       value = 3829532 = 0x3a6f1c
*       -> MESSAGE FROM CLIENT (Internet Address 150.12.0.10, port 1027):
*       Hello out there
*
* RETURNS: Never, or ERROR if a resources could not be allocated.
*/
void tcpServer( void )
{
	/*struct sockaddr_in  serverAddr;*/    /* server's socket address */
	struct sockaddr_in  clientAddr;    /* client's socket address */
	int                 sockAddrSize;  /* size of socket address structure */
	int                 Socket;           /* socket file descriptor */
	int                 newsocket;        /* socket descriptor from accept */
	int 				val;

	InitServerFsm( );
	NetInitComplete = TRUE;

	if( channel_open_as_server( &Socket ) == ERROR )
		return;

/*	if(ioctl( Socket, FIONBIO, 1 )==ERROR )
		BYPrintf("error\n");
*/
	val = 1;
	sockAddrSize = sizeof(struct sockaddr_in);
	while (1)
	{
		if ((newsocket = accept (Socket, (struct sockaddr *) &clientAddr,
			&sockAddrSize)) == ERROR)
		{
		}
		else
		{
			NewClientHdl( newsocket, clientAddr );  
		}

		taskDelay(2);
	}
}

VOID tcpServerSendRecv( VOID )
{
	US  port_num;

	if( NetInitComplete == TRUE )
	{
		TcpipSendRecvHdl( 0 );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -