套接字或不同套接字上有多个线程? [英] More than one thread on a socket, or different socket?

查看:80
本文介绍了套接字或不同套接字上有多个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有个好消息 - 我的远程桌面应用程序运行良好,远程屏幕截图实际通过的程度:)



我现在要做的是将计算机连接到键盘时将这些键发送到远程计算机,以便我可以完全控制键盘(我已经制作了一个键盘记录器)



我也想捕捉鼠标事件,我已经可以做了。



唯一的问题我我正在通过端口8085运行SendScreen线程,为了清晰的连接,我还想要一个单独的键击线程,另一个用于鼠标移动,包括。点击。



我想要一些建议:我应该在不同的端口上使用3个完全不同的TCPClient(如果是这样,我可以将哪些端口用于TCP?),或者我可以放端口8085上的所有3个线程?我想这会出现错误,因为它可能会说端口正在使用。



谢谢,



Ricky

Hello,

I have good news- my remote desktop app is working great, to the extent where the remote screenshots actually get through :)

What I want to do now is to keylog my computer when it's connected to send those keys through to the remote computer so that I can fully control the keyboard (I made a keylogger already)

I also want to capture mouse events, which I can do already.

The only problem I have is that I'm running the SendScreen thread through port 8085, and I also want, for clarity of connections, a separate thread for key strokes, and yet another for mouse movements, incl. clicking.

I would like some advice: should I use 3 completely different TCPClients on different ports (if so, which ports can I use for TCP?), or can I put all 3 threads on port 8085? I'm thinking that this will come up with an error as it'll probably say that the port is in use.

Thanks,

Ricky

推荐答案

您可以在端口8085上打开一个连接,而不是使用3个独立的端口(和3个独立的连接)。线程都可以使用它,并且(我认为!)只要您使用SyncLock将连接包装在锁定对象中。每当一个线程发送一条消息时,你就会在一个锁定对象上调用SyncLock,发送消息,然后释放锁定。



现在你必须提出自己的应用程序水平通信协议。消息将是命令值,然后是有效负载值。在你的情况下,我正在发送一个SCREENSHOT,这里是它的数据,或者我正在发送一个KEYSTROKE,这里是它的数据,或者......你明白了。



您是否为每个帧发送完整的屏幕截图?你很可能会重载机器之间的连接。对于1280x1024的屏幕尺寸,每像素32位,这是每帧5MB的数据!对于比千兆速度慢的连接,这不会很好。
Instead of using 3 separate ports (and 3 separate connections), you open one connection on port 8085. The three threads can all use it, and (I think!) so long as you wrap the connection in a lock object using SyncLock. Whenever a thread sends a message, you call SyncLock on a lock object, send the message, then release the lock.

Now you have to come up with your own application level communication protocol. A message would be a command value and then a payload value. In your case, "I'm sending a SCREENSHOT and here's the data for it", or "I'm sending a KEYSTROKE and here's the data for it", or... You get the idea.

Are you sending full screenshots for every frame?? You could very well be overloading the connection between machines. For a screen size of 1280x1024, at 32-bit per pixel, that's 5MB of data PER FRAME! This wouldn't work well over connections slower than Gigabit speeds.


这篇关于套接字或不同套接字上有多个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆