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

📄 printserver.cpp

📁 本源码为移动公司话费查询中间件TUXEDO使用的实例
💻 CPP
字号:
// PrintServer.cpp : Defines the entry point for the console application.
//

#include <string.h>

#include <stdio.h>
#include <signal.h>

#include "TCPListen.h"
#include "OS.h"

void catch_c(int sig)
{
	printf("Catch succeed!\n");
	exit(1);
}

#ifdef _WIN32
int InitSocket()
{
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;
	wVersionRequested = MAKEWORD( 2, 2 );
	err = WSAStartup( wVersionRequested, &wsaData );
	if ( err != 0 ) 
	{
		/* Tell the user that we could not find a usable */
		/* WinSock DLL.                                  */
		return 0;
	}
 
	/* Confirm that the WinSock DLL supports 2.2.*/
	/* Note that if the DLL supports versions greater    */
	/* than 2.2 in addition to 2.2, it will still return */
	/* 2.2 in wVersion since that is the version we      */
	/* requested.                                        */
 
	if ( LOBYTE( wsaData.wVersion ) != 2 ||
			HIBYTE( wsaData.wVersion ) != 2 ) {
		/* Tell the user that we could not find a usable */
		/* WinSock DLL.                                  */
		WSACleanup( );
		return 0; 
	}
	return 1;	/* The WinSock DLL is acceptable. Proceed. */
}
#endif

int main(int argc, char* argv[])
{
	CTCPListen tcpListen;
	char chLog[100],chTime[21];

#ifdef _WIN32
	if(InitSocket()!=1)
	{
		printf("Init socket failed!");
		return 0;
	}
#endif

	OS::GetSysDate(chTime,1);

	signal(SIGINT,catch_c);
	CSHPPSession::Initialize();

	#ifndef _WIN32
		sprintf(chLog,"/home/oracle/server/p_%s.log",chTime);
	#else
		sprintf(chLog,"p_%s.log",chTime);
	#endif //_WIN32
	OSThread::TOpen(chLog);
	printf("Log file name:");
	printf(chLog);
	printf("\n");
	OS::GetSysDateTime(chTime);

	tcpListen.Start();
	sprintf(chLog,"%s服务器开始启动!\r\n",chTime);
	OSThread::TWrite(chLog,strlen(chLog));
	printf(chLog);

	tcpListen.Join();
	tcpListen.Close();

	OS::GetSysDateTime(chTime);
	sprintf(chLog,"%服务器关闭\r\n",chTime);
	OSThread::TWrite(chLog,strlen(chLog));
	OSThread::TClose();	
	printf(chLog);
	return 0;
}

⌨️ 快捷键说明

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