热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

急!!抓屏后用socket发送数据奇慢!

最近要做一个远程控制的软件,抓屏后把数据分成768个数据包用TCP协议发送,但是发送数据奇慢,要3~5秒才能发送一屏,而且发送和接收过程中程序就象死了一样,CPU占用100%,这是怎么回事?请各位高手
最近要做一个远程控制的软件,抓屏后把数据分成768个数据包用TCP协议发送,但是发送数据奇慢,要3~5秒才能发送一屏,而且发送和接收过程中程序就象死了一样,CPU占用100%,这是怎么回事?请各位高手帮忙,分不够可以加!谢谢!

12 个解决方案

#1



压缩一下再发呀

#2


试试你的网络传输部分,传输其他的数据是否有问题。
抓拍的图像应该是bmp格式,将它转换成jpg格式然后传输

#3


抓屏后把数据分成768个数据包用TCP协议发送,但是发送数据奇慢,要3~5秒才能发送一屏

====================================================
很正常。

我做了一個,可以討論一下

http://www.xdowns.com/soft/1/118/2007/Soft_38204.html

#4


假定你的是1024*768的分辨率,每个象素3字节,总共1024*768*3=2.25MB,假定3秒发完,带宽需求为2.25/3*10大概是10Mbps,即使在局域网,这也是比较高的发送率。所以你必须保证发送前有很高压缩比的算法进行压缩才行,不能直接发

至于CPU占有率问题,应该是你在发送失败后不顾网络堵塞情况循环重发导致,这样不会加快你发送,反而会减缓你发送。任何不阻塞的循环方式发送都可能导致CPU占有率的上升

#5


这种东西估计要对socket非常熟悉才行,三言两语说不清

#6


fox1999同志,你做的红狐软件很厉害啊,抓屏速度很快,而且占用资源也不多,能不能交流一下啊?谢谢!

#7


同意 arong1234 

#8


arong1234:
我是用本机给本机发送的,我的网卡是10M/100M自适应的,应该足够用的呀~

#9


arong1234: 
如何防止网络堵塞时重发数据呢?如果加一个Sleep()的话发送时间会更长呀,请指点!谢谢!

#10


使用钩子函数,或者使用虚拟显卡驱动。WH_CBT钩子截图 瞬间可能有没画完的,截图瞬间多截几张
时间间隔是130毫秒,最好设定时器
CBTProc
The CBTProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. The system calls this function before activating, creating, destroying, minimizing, maximizing, moving, or sizing a window; before completing a system command; before removing a mouse or keyboard event from the system message queue; before setting the keyboard focus; or before synchronizing with the system message queue. A computer-based training (CBT) application uses this hook procedure to receive useful notifications from the system. 

The HOOKPROC type defines a pointer to this callback function. CBTProc is a placeholder for the application-defined or library-defined function name. 

LRESULT CALLBACK CBTProc(
  int nCode,      // hook code
  WPARAM wParam,  // depends on hook code
  LPARAM lParam   // depends on hook code
);
 
Parameters
nCode 
Specifies a code that the hook procedure uses to determine how to process the message. This parameter can be one of the following values: Value Meaning 
HCBT_ACTIVATE The system is about to activate a window. 
HCBT_CLICKSKIPPED The system has removed a mouse message from the system message queue. Upon receiving this hook code, a CBT application must install a WH_JOURNALPLAYBACK hook procedure in response to the mouse message. 
HCBT_CREATEWND A window is about to be created. The system calls the hook procedure before sending theWM_CREATE orWM_NCCREATE message to the window. If the hook procedure returns a nonzero value, the system destroys the window; theCreateWindow function returns NULL, but theWM_DESTROY message is not sent to the window. If the hook procedure returns zero, the window is created normally. 
 At the time of the HCBT_CREATEWND notification, the window has been created, but its final size and position may not have been determined and its parent window may not have been established. It is possible to send messages to the newly created window, although it has not yet received WM_NCCREATE or WM_CREATE messages. It is also possible to change the position in the Z order of the newly created window by modifying the hwndInsertAfter member of the CBT_CREATEWND structure. 
HCBT_DESTROYWND A window is about to be destroyed. 
HCBT_KEYSKIPPED The system has removed a keyboard message from the system message queue. Upon receiving this hook code, a CBT application must install a WH_JOURNALPLAYBACK_hook hook procedure in response to the keyboard message. 
HCBT_MINMAX A window is about to be minimized or maximized. 
HCBT_MOVESIZE A window is about to be moved or sized. 
HCBT_QS The system has retrieved a WM_QUEUESYNC message from the system message queue. 
HCBT_SETFOCUS A window is about to receive the keyboard focus. 
HCBT_SYSCOMMAND A system command is about to be carried out. This allows a CBT application to prevent task switching by means of hot keys. 


If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. 

wParam 
Depends on the nCode parameter. For details, see the following Remarks section. 
lParam 
Depends on the nCode parameter. For details, see the following Remarks section. 
Return Values
The value returned by the hook procedure determines whether the system allows or prevents one of these operations. For operations corresponding to the following CBT hook codes, the return value must be 0 to allow the operation, or 1 to prevent it: 

HCBT_ACTIVATE
HCBT_CREATEWND
HCBT_DESTROYWND
HCBT_MINMAX
HCBT_MOVESIZE
HCBT_SETFOCUS
HCBT_SYSCOMMAND

For operations corresponding to the following CBT hook codes, the return value is ignored: 

HCBT_CLICKSKIPPED
HCBT_KEYSKIPPED
HCBT_QS

#11


我用的是触发钩子截图,然后延时130毫秒在截。

#12


连续的截图造成 cpu负担过重,所以应该选用钩子函数或虚拟显卡驱动,来获得变化的图像,变化的图像截图时有
时可能不完整所以要多截几张!!!

推荐阅读
author-avatar
WINGZERO哥哥
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有