资源简介
该程序用于模拟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注意事项
相关资源
- 编写简单的RMI程序 多线程web 服务器
- 多线程生产者消费者模式
- ISO7816 协议标准
- 多线程实例:桌面智能弹球小游戏
- WPF多线程演示
- 易语言:多线程传多变量的最稳定方
- 智能卡PCSC读卡器指令发送工具
- 排队买票多线程问题
- 强大的完善的 活动抽奖系统适合各单
- 十字路口红绿灯交通情况模拟
- Qt 多线程连接数据库——数据库
- 易语言多线程端口扫描源码
- POSIX多线程程序设计中文版源码
- iso/iec 7816-4中文版
- 易语言md5定向爆破源码
- 多线程扫描工具
- Delphi.High.Performance.Applications.Concurren
- Qt5的多线程小程序,实现按钮开关线
- 控制台串口通信程序
- POSIX多线程程序设计中文版pdf
- 使用多线程及图像分块实现图像处理
- 图像处理中使用多线程及图像分块实
- p2p文件共享系统 含代码和文档
- 武汉理工大学面向对象与多线程综合
- 多线程编程指南[中文完整翻译版] –
- QT多线程实现图片以缩略图形式显示
- qt利用线程实现多任务
- 基于socket的多线程QQ聊天系统(代码
- UDP socket 多线程
- linux多线程编程书籍
评论
共有 条评论