资源简介

该程序用于模拟Sjl06型加密机的功能,创建一个socket,用于模拟sjl06与智能卡的通讯

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “Server.h“
#include “SJL06SVR.H“

DWORD WINAPI ServerThread(LPVOID lpvParam)
{
stSvrParam* pParam = (stSvrParam* )lpvParam;
if(pParam == NULL)
return 0;

while(*(pParam->plStopFlag) == 0){
sockaddr_in addr;
int addrlen = sizeof(addr);
SOCKET clientSocket = accept(pParam->listenSocket (sockaddr* )&addr &addrlen);
if(clientSocket != INVALID_SOCKET){
pParam->clientSocket = clientSocket;
CSJL06Svr svr(clientSocket);
svr.DoWork();
}
pParam->clientSocket = INVALID_SOCKET;
}

return 0;
}

CServerManager::CServerManager()
{
m_socket = INVALID_SOCKET;
m_lStopFlag = 0;
m_hServerThread = NULL;
}

CServerManager::~CServerManager()
{
StopService();
}

UINT CServerManager::StartService(char* szIP int nPort)
{
if(m_hServerThread != NULL)
return SERVICE_STARTUP_OK;

m_lStopFlag = 0;

UINT nRetVal = SERVICE_STARTUP_OK;
__try{
m_socket = socket(AF_INET SOCK_STREAM 0);
if(m_socket == INVALID_SOCKET){
nRetVal = SERVICE_STARTUP_E_CREATE_SOCKET;
__leave;
}

sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(szIP);
addr.sin_port = htons(nPort);

if(bind(m_socket (sockaddr* )&addr sizeof(addr)) == SOCKET_ERROR){
nRetVal = SERVICE_STARTUP_E_BIND_SOCKET;
__leave;
}

if(listen(m_socket SOMAXCONN) == SOCKET_ERROR){
nRetVal = SERVICE_STARTUP_E_LISTEN_SOCKET;
__leave;
}

m_stSvrParam.plStopFlag = &m_lStopFlag;
m_stSvrParam.listenSocket = m_socket;
m_stSvrParam.clientSocket = INVALID_SOCKET;
DWORD dwServiceThreadId;
m_hServerThread = CreateThread(NULL 0 ServerThread &m_stSvrParam 0 &dwServiceThreadId);
if(m_hServerThread == NULL){
nRetVal = SERVICE_STARTUP_E_CREATE_THREAD;
__leave;
}

}
__finally{
if((nRetVal != SERVICE_STARTUP_OK) && (m_socket != INVALID_SOCKET)){
closesocket(m_socket);
m_socket = INVALID_SOCKET;
}
}

return nRetVal;
}

BOOL CServerManager::StopService()
{
InterlockedExchange(&m_lStopFlag 1);

if(m_stSvrParam.clientSocket != INVALID_SOCKET){
closesocket(m_stSvrParam.clientSocket);
m_stSvrParam.clientSocket = INVALID_SOCKET;
}

if(m_socket != INVALID_SOCKET){ 
closesocket(m_socket);
m_socket = INVALID_SOCKET;
}

HANDLE phThread[3];
DWORD dwCount = 0;
if(m_hServerThread != NULL)
phThread[dwCount++] = m_hServerThread;
WaitForMultipleobjects(dwCount phThread TRUE 5000);
for(DWORD dwI = 0; dwI < dwCount; dwI++)
CloseHandle(phThread[dwI]);

m_hServerThread = NULL;

return TRUE;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-09-01 13:21  SJL06_Simulator\
     文件        3741  2007-12-28 11:32  SJL06_Simulator\ReadMe.txt
     目录           0  2013-09-01 11:07  SJL06_Simulator\Release\
     文件        4541  2013-09-01 11:07  SJL06_Simulator\Release\Server.obj
     文件       15396  2013-09-01 11:07  SJL06_Simulator\Release\SJL06SVR.obj
     文件       40960  2013-09-01 11:07  SJL06_Simulator\Release\SJL06_Simulator.exe
     文件       10322  2013-09-01 11:07  SJL06_Simulator\Release\SJL06_Simulator.obj
     文件     5813112  2013-09-01 11:07  SJL06_Simulator\Release\SJL06_Simulator.pch
     文件        2556  2013-09-01 11:00  SJL06_Simulator\Release\SJL06_Simulator.res
     文件       18132  2013-09-01 11:07  SJL06_Simulator\Release\SJL06_SimulatorDlg.obj
     文件         836  2013-09-01 11:07  SJL06_Simulator\Release\StdAfx.obj
     文件       50176  2013-09-15 06:44  SJL06_Simulator\Release\vc60.idb
     目录           0  2012-06-15 13:56  SJL06_Simulator\res\
     文件         692  2007-12-28 11:32  SJL06_Simulator\Resource.h
     文件        1078  2007-12-28 11:32  SJL06_Simulator\res\SJL06_Simulator.ico
     文件         407  2007-12-28 11:32  SJL06_Simulator\res\SJL06_Simulator.rc2
     文件        2627  2007-12-28 11:32  SJL06_Simulator\Server.cpp
     文件         887  2007-12-28 11:32  SJL06_Simulator\Server.h
     文件       11187  2007-12-28 11:32  SJL06_Simulator\SJL06SVR.CPP
     文件         677  2007-12-28 11:32  SJL06_Simulator\SJL06SVR.H
     文件       35544  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.aps
     文件        1054  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.clw
     文件        2283  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.cpp
     文件        4573  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.dsp
     文件         555  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.dsw
     文件        1423  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.h
     文件       66560  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.ncb
     文件       54784  2013-09-01 13:21  SJL06_Simulator\SJL06_Simulator.opt
     文件        2218  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.plg
     文件        5091  2007-12-28 11:32  SJL06_Simulator\SJL06_Simulator.rc
     文件        3646  2007-12-28 11:32  SJL06_Simulator\SJL06_SimulatorDlg.cpp
............此处省略8个文件信息

评论

共有 条评论