远程桌面监控 (3)
好久没更了。之前忘了,,嘤嘤嘤我悔过= =
视频传输
现在就来讲讲视频传输:
(由于没啥时间,我就讲个大概)
首先是 服务器传输指令给客户端:
//视频
void CDMMserverDlg::OnBnClickedSeeButton()
{
char s[100] = { 3 };
int res = send(socketname, (char*)&s, sizeof(s), 0);
if (res >= 0)
MessageBox(L"执行成功\n注意,请不要重复按下监控按钮,在监控该用户期间,请在关闭该窗口后再点击选择其他用户。");
else
MessageBox(L"执行失败");
if (NULL == m_pTipDlg)
{
// 创建非模态对话框实例
m_pTipDlg = new m_SEE(this);
m_pTipDlg->Create(IDD_SEE_DIALOG, this);
}
// 显示非模态对话框
m_pTipDlg->ShowWindow(SW_SHOW);
recvIMG = CreateThread(NULL, 0, recvImg, m_pTipDlg, 0, NULL);
}
显然我没有去改。。。(所以就是有个bug没解决。就是多开的问题)
然后 就是客户端接收:(同样的在接收函数里面判断指令)
else if (recvBuf[0] == 3)
{
IMGHAN = CreateThread(NULL, 0, IMG, pdlg, 0, NULL);
}
//
//接收线程
DWORD WINAPI IMG(LPVOID lpParamter)
{
CDMMClientDlg*pdlg = (CDMMClientDlg *)lpParamter;
while (pdlg->IMGYN == false)
{
if (sendImg(pdlg) < 0)
break;
}
pdlg->IMGYN = false;
return -1;
}
/
//
接收之后就是截图发送图片:
BOOL sendImg( CDMMClientDlg*pdlg)
{
HBITMAP hb = pdlg->GetScreenBitmap();
CImage hm;
hm.Attach(hb);
CImage img;
pdlg->CreateSmallPic(hm);
hm.Destroy();
img.Load(_T("bitmap.bmp"));
//1.发送图片的头
struct imgHead head;
head.with = img.GetWidth();
head.higth = img.GetHeight();
head.BPP = img.GetBPP();
head.step = img.GetPitch();
int step = img.GetPitch();
if (step > 0)
{
head.rowSize = step;
}
else
{
head.rowSize = -step;
}
int res = send(sock_IMG, (char *)&head, sizeof(head), 0);
if (res < 0)
{
pdlg->MessageBox(L"服务器断开");
return -1;
}
//2.发送图片的数据部分
unsigned char *pbuf = (unsigned char *)malloc(head.rowSize);
unsigned char * pImg = (unsigned char *)img.GetBits();
for (int i = 0; i < head.higth; i++)
{
//发送一行s
memcpy_s(pbuf, head.rowSize, pImg + i * step, head.rowSize);
int needSend = head.rowSize;
unsigned char *p = pbuf;
while (1)
{
res = send(sock_IMG, (char *)p, needSend, 0);
if (res <= 0)
{
pdlg->MessageBox(L"服务器断开");
return -1;
}
needSend -= res;
p += res;
if (needSend == 0)
{
break;
}
}
}
free(pbuf);
pbuf = NULL;
return 0;
}
然后服务端接收:
DWORD WINAPI recvImg(LPVOID lpParamter)
{
m_SEE *pdlg = (m_SEE *)lpParamter;
pdlg->SEECHECK = 0;
//cleanBuff(sock_IMGname);
while (TRUE)
{
if (pdlg->SEECHECK == true)
{
char s[100] = { 5 };
int res = send(socketname, (char*)&s, sizeof(s), 0);
cleanBuff(sock_IMGname);
return -1;
}
//1接收图片的头
struct imgHead head;
int res = recv(sock_IMGname, (char *)&head, sizeof(head), 0);
if (res < 0)
{
return -1;
}
CImage vsImg;
vsImg.Create(head.with, head.higth, head.BPP, 0);
//2.接收图片的数据部分
unsigned char *pbuf = (unsigned char *)malloc(head.rowSize);
unsigned char * pImg = (unsigned char *)vsImg.GetBits();
for (int i = 0; i < head.higth; i++)
{
int needRecv = head.rowSize;
unsigned char *p = pbuf;
while (1)
{
res = recv(sock_IMGname, (char *)p, needRecv, 0);
if (res < 0)
{
return -1;
}
needRecv -= res;
p += res;
if (needRecv == 0)
{
break;
}
}
//memcpy_s(pbuf, head.rowSize, pImg+i*step, head.rowSize);
memcpy_s(pImg + i * head.step, head.rowSize, pbuf, head.rowSize);
}
free(pbuf);
pbuf = NULL;
pdlg->showImgInCtr(IDC_STATIC, vsImg);
}
}
先这样咕咕咕着。后面看到了再写注释。
我会贴我的具体实现的。(禁止盗用)