473,772 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sockets for sending/receiving mouse movement

I am creating a simple server application, that will listen for
incoming mouse coordinates and then move the mouse accordingly. So
basically it's like a very simple VNC server without and screen
display. I have this basic part working. The problem is that response
time is really bad. It seems like the server is not receiving the data
fast enough to be able to move the mouse so that it appears to be in
sync with the movement on the client machine. I'm using a buffer size
of 32, and just sending my commands from the client as the same length
every time. When they come in, I add them to a queue, then have a
separate thread that processes the movement in the queue as it comes
in. I figured this was the fastest way, but it doesn't seem to be fast
enough. Clearly there is a better way of doing this that I'm not
seeing. Any suggestions?

My code looks something like this:

Public Sub dataArrival(ByV al ar As IAsyncResult)

Dim bytesRead As Integer = handler.EndRece ive(ar)

If bytesRead 0 Then

content = Encoding.ASCII. GetString(state .buffer, 0,
bytesRead)

eventQueue.Add( content)

handler.BeginRe ceive(state.buf fer, 0,
StateObject.Buf ferSize, 0, New AsyncCallback(A ddressOf dataArrival),
state)

end if

end sub
Aug 11 '08 #1
5 2330
I suspect that the problem may be a delay in the sending code, not the
receive code. Does anything look suspicious there?

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Aug 11 '08 #2
The sending code is written in C because it's cross platform. Anytime
there is mouse movement, it simply calls the following code with a
string like "x=100,y=20 0"

send(sockfd, [data bytes], [data length], 0);

I've tried sampling the mouse movement at different intervals, but
doing it too slow gets choppy movement, and doing it at an appropriate
rate seems to send data faster than it can reach the server in time to
be processed in what would appear as realtime to the user. This is
always run over a LAN, so I don't see how I could possibly be sending
too much data. How can I tell exactly where the delay is?
On Aug 11, 2:39*pm, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
I suspect that the problem may be a delay in the sending code, not the
receive code. *Does anything look suspicious there?

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardands oftware.netfor details and contact information.
Aug 11 '08 #3
The sending code is written in C because it's cross platform. Anytime
there is mouse movement, it simply calls the following code with a
string like "x=100,y=20 0"

send(sockfd, [data bytes], [data length], 0);

I've tried sampling the mouse movement at different intervals, but
doing it too slow gets choppy movement, and doing it at an appropriate
rate seems to send data faster than it can reach the server in time to
be processed in what would appear as realtime to the user. This is
always run over a LAN so I can't see how I could be sending too much
data. How can I tell exactly where the delay is?
On Aug 11, 2:39*pm, "Dick Grier" <dick_grierNOSP AM@.msn.comwrot e:
I suspect that the problem may be a delay in the sending code, not the
receive code. *Does anything look suspicious there?

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardands oftware.netfor details and contact information.
Aug 11 '08 #4
Hi,

There is significant latency in TCP/IP (especially if a wireless connection
is involved). I try to match my sending data size to the actual TCP/IP
packet size, to minimize this. Natrually, this is not practical in your
case. Adding the data to a queue adds additional latency on the consuming
side (IMO, I'd just process it directly).

Perhaps you should try to use UDP instead of TCP. UDP isn't connection
orriented, so it has much lower inherent latencies.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Aug 12 '08 #5
Hi,

There is significant latency in TCP/IP (especially if a wireless connection
is involved). I try to match my sending data size to the actual TCP/IP
packet size, to minimize this. Natrually, this is not practical in your
case. Adding the data to a queue adds additional latency on the consuming
side (IMO, I'd just process it directly).

Perhaps you should try to use UDP instead of TCP. UDP isn't connection
orriented, so it has much lower inherent latencies.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Aug 12 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
32654
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left mouse click and the button under the mouse is clicked. Yours, Jonas
3
3709
by: Robert A. van Ginkel | last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I can see if all the data is on the other side of the connection. I got as answer that I should use the blocking property. I tried this I don't see any diffents, I am sending 10Mb and the Send/BeginSend command doesn't wait till the data is on the remotepoint. Can somebody pls. explain this. Regards Robert.
6
7000
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
4
317
by: WAkthar | last post by:
I am in the process of converting an MFC client and server application to C#. The communication between the client and server was done using simple WM_COPYDATA. I want to use sockets for the C# version. Can someone show me how to send and receive data structures using sockets?
0
4292
by: J008 | last post by:
Just looking for some insight as to why the callback "BeginReceiveFromCallback" is not being called in my "Receive" Subroutine below (when I call BeginReceiveFrom). I am trying to read data asynchronously using UDP. I have implemented Send and Connect subroutines in a similar way, and they both seem to work. When I put a breakpoint in the callbacks for Send and Connect, I hit them, and I can see the results I want. However, when I put a...
14
11922
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was doing something was really inefficient and could reduce 10 lines of code with 2, etc. For reading, I am using a TcpClient and I call NetworkStream ns = client.GetStream(); to get a stream stream.Read(buffer, 0, buffer.Length);
3
3612
by: garyusenet | last post by:
I have a programme written in C++, the programme is unmanaged and is an executable, i don't have any source code. I'm writing a C# program. I want to (a) start the programme minimized. (b) send keystrokes to the programme, and mouse strokes. Can you please tell me how I would do this assuming the programme is called "c:\programme.exe"
4
6977
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I just gotta fix it. I need to make some calculations on the measurements and VB6 is my language. Yes, the system mouse will corrupt the measurement, but it's an auditing function and that's acceptable.
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.