// TransBmp.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "TransBmp.h"
#include "MainFrm.h"
#include "TransBmpDoc.h"
#include "TransBmpView.h"
#include "common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define LINESIZE 1024
HANDLE g_hEvent;
/////////////////////////////////////////////////////////////////////////////
// CTransBmpApp
BEGIN_MESSAGE_MAP(CTransBmpApp, CWinApp)
//{{AFX_MSG_MAP(CTransBmpApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTransBmpApp construction
CTransBmpApp::CTransBmpApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CTransBmpApp object
CTransBmpApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CTransBmpApp initialization
BOOL CTransBmpApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
///////////////////////////////////////////////////////////////////////////////////////////
//等待连接,连接成功后显示界面显示传来的位图
Init();
///////////////////////////////////////////////////////////////////////////////////////////
//主线程中进行四循环监听来自玩家的连接
SOCKET hAcceptSocket;
hAcceptSocket=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
int reuse = 1;
setsockopt(hAcceptSocket, SOL_SOCKET,SO_DONTLINGER|SO_REUSEADDR, (char FAR *)&reuse, sizeof(int));
struct sockaddr_in LocalAddr; //本端IP地址 Local Address
LocalAddr.sin_family = AF_INET;
LocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
LocalAddr.sin_port = htons((short int)(LOG_SERVER_PORT));//
bind(hAcceptSocket,(struct sockaddr*)&LocalAddr,sizeof(struct sockaddr));
TRACE("----------------------------------------------------------\n");
TRACE("Recv Server listen on PORT %d\n", LOG_SERVER_PORT);
TRACE("----------------------------------------------------------\n");
listen(hAcceptSocket,MAX_CONNECTION_NUM);
char szIP[16]; SOCKET hPlayerCommSocket;
struct sockaddr RemoteAddr;
int AddrLen = sizeof(struct sockaddr);
if ((hPlayerCommSocket = accept (hAcceptSocket, (struct sockaddr FAR *)&RemoteAddr,
(int FAR* ) &AddrLen))!=INVALID_SOCKET)
{
memset(szIP,0,16);
GetPeerIPBySocket(hPlayerCommSocket,szIP);
TRACE("Accept new connection from IP = %s on sock : %d\n",
szIP,hPlayerCommSocket);
_beginthread(PlayerCommThread,0,(LPVOID)hPlayerCommSocket);
}
///////////////////////////////////////////////////////////////////////////////////////////
// To create the main window, this code creates a new frame window
// object and then sets it as the application's main window object.
g_hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
int Value;
ResetEvent(g_hEvent);
Value=WaitForSingleObject(g_hEvent,60000000);
if (Value==WAIT_TIMEOUT)
{
AfxMessageBox("等待超时!");
return false;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CTransBmpDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CTransBmpView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CTransBmpApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CTransBmpApp message handlers
//通信主线程
///////////////////////////////////////////////////////////////////////////////////////////////
//一个玩家一个该线程,用于该玩家的通信收/发
//该线程中代表该玩家的唯一指针是pNewPlayer
void convert_long ( unsigned char * buffer )
{
unsigned char Temp;
Temp = *( ( unsigned char * ) buffer );
*( ( unsigned char * ) buffer ) = *( ( unsigned char * ) ( buffer + 3 ) );
*( ( unsigned char * ) ( buffer + 3 ) ) = Temp;
Temp = *( ( unsigned char * ) ( buffer + 1 ) );
*( ( unsigned char * ) ( buffer + 1 ) ) = *( ( unsigned char * ) ( buffer + 2 ) );
*( ( unsigned char * ) ( buffer + 2 ) ) = Temp;
}
DWORD g_dwPlayerCommThreadId = 0;
void PlayerCommThread(LPVOID hSocket)
{
SOCKET hPlayerCommSocket = (SOCKET) hSocket;
g_dwPlayerCommThreadId = GetCurrentThreadId();
TRACE("----------------------------------------------------------\n");
TRACE("PlayerCommThread (ID=0x%x) started on sock=%d!\n",
g_dwPlayerCommThreadId,hPlayerCommSocket);
TRACE("----------------------------------------------------------\n");
char szRecvBuf[LINESIZE];
///////////////////////////////////////////////////////////////////////////////////////////
CString strFileName(_T("test.bmp"));
CFile File(strFileName, CFile::modeReadWrite|CFile::modeCreate);
///////////////////////////////////////////////////////////////////////////////////////////
//死循环中接收
//每接收一个包就处理一个,其实这里就只处理两种包:
//1 即登录请求身份验证,通过后发OK,若不通过,则发FAIL
//2 离开消息
int nBytesRecv;
char szIP[16];
memset(szIP,0,16);
GetPeerIPBySocket(hPlayerCommSocket,szIP);
///////////////////////////////////////////////////////////////////////////////////////////
st
weixin_40545943
- 粉丝: 1
- 资源: 5
最新资源
- 全科目福建省中等职业学校学业水平考试说明
- "移相全桥DCDC电源的PI双闭环控制技术,以400V输入电压实现48V/20A输出电流的Matlab与Simulink仿真研究",移相全桥dcdc双闭环pi控制,电压外环,电流内环,matlab仿真
- 基于乔列斯基分解的三维随机场生成与空间变异性分析:Matlab实现及Flac随机场模型建立,三维随机场 空间变异性 三维互相关随机场 随机场 基于乔列斯基分解生成,主要采用Matlab生成随机场数据
- 三相PWM整流器:电压电流双闭环控制的Matlab Simulink模型仿真与性能分析,实现功率因数近1且低THD仅1.2%的直流电压输出控制研究,三相PWM整流器闭环仿真,电压电流双闭环控制,输出直
- 基于Matlab的双卡尔曼滤波算法:电池SOC估计的精确稳定优化策略,基于matlab的双卡尔曼滤波算法 第一步使用了卡尔曼滤波算法,用电池电压来修正SOC,然后将修正后的SOC作为第二个卡尔曼滤波
- 稀土领域生产一体化管控系统案例
- 基于最优占空比优化的异步电机模型预测转矩控制策略:一种综合电压矢量与占空比的最小化策略实现方法,基于最优占空比优化的异步电机模型预测转矩控制 占空比模型预测转矩控制方法是在每一个采样周期里先根据价值函
- 打开浏览器网页用油猴自动签到
- "基于Matlab/Simulink的线性时变模型预测控制(LTV-MPC)仿真研究:隐式、自适应与时变MPC的闭环分析",线性时变模型预测控制LTV-MPC Matlab+simulink仿真(2
- "《基于Matlab的配电网两阶段鲁棒故障恢复方法研究:复现自中科院一区期刊IEEE Transactions on Power Systems》",1020-(顶刊复现)配电网两阶段鲁棒故障恢复(m
- Multisim 74LS161+138+04+00+86实现8路彩灯
- "Carsim联合仿真模型验证:十四自由度车辆动力学模型精确验证与实时监控",联合仿真模型验证Carsim+车辆动力学模型(十四自由度) 软件使用:Carsim2019.0+Matlab Simu
- ESXi-8.0U3c-24414501-standard-customized.v24.4.iso
- 赫少付费v1 (1).zip
- "基于300kw直驱永磁同步电机的Matlab Simulink仿真模型:风电并网与优化学习资源",300kw直驱永磁同步电机 Matlab simulink仿真模型风电并网,仿真波形好,适合学习
- 基于CarSim与Simulink的PID控制算法在三车队列控制中的应用研究,队列控制 carsim联合simulink pid控制 实现3辆车的队列控制,跟随头车车速变化,保合理车距 ,核心关键
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈