资源简介
该程序用于模拟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个文件信息
- 上一篇:a* 算法 人工智能 拼图游戏
- 下一篇:部署ReportViewer注意事项
相关资源
- 多线程并发同步爸爸妈妈苹果橘子问
- 单片机多任务实现
- linux多人聊天室管理系统
- 操作系统实验多线程读者写者优先问
- Win32多线程程序设计.侯捷.超清完美版
- 安卓app之间的socket通信,支持多线程
- Pker多线程后台极速扫描工具2.01修正版
- Linux编程手册-多线程-详细资料.rar
- QT多线程实现图片以缩略图形式显示图
- PC/SC规范用于智能卡开发使用
- CPU Cache and Memory Ordering
- 多线程ftp客户端可以实现多站点和上
- USB CCID 规范
- 武汉理工大学 面向对象与多线程综合
- 多线程网络文件传输的设计与实现
- 基于Qt实现的多线程客户端与服务器
- QT调用basler SDK 多线程多相机采集代码
- 用PyQT5多线程爬取轻小说工具
- 并行计算多线程求π以及矩阵转置
- 智能卡开发者指南
- 可同时搜索多个文件的多线程快速搜
- 使用三种VC的多线程同步方法编写一个
- QT+Opencv2+VS2012 使用多线程显示网络摄
- 多线程TCP服务器运行程序
- Linux多线程服务端编程 - 陈硕(高清完
- 并发编程笔记(httpswww.bilibili.comvide
- DevExpress RichEditControl 多线程插入表格
- 嵌入式实时操作系统的多线程计算:
- Linux多线程服务端编程 - 陈硕高清完整
-
zw_ob
jective-C高级编程iOS与OSX多线程和
评论
共有 条评论