473,378 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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(ByVal ar As IAsyncResult)

Dim bytesRead As Integer = handler.EndReceive(ar)

If bytesRead 0 Then

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

eventQueue.Add(content)

handler.BeginReceive(state.buffer, 0,
StateObject.BufferSize, 0, New AsyncCallback(AddressOf dataArrival),
state)

end if

end sub
Aug 11 '08 #1
5 2293
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=200"

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_grierNOSPAM@.msn.comwrote:
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.hardandsoftware.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=200"

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_grierNOSPAM@.msn.comwrote:
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.hardandsoftware.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
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...
3
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...
6
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
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#...
0
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...
14
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...
3
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...
4
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.