Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 899057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:09:13+00:00 2026-05-15T15:09:13+00:00

I am trying to make a socket server that spews mouse move events, in

  • 0

I am trying to make a socket server that spews mouse move events, in Cocoa.

This thread: Mouse tracking daemon

has info regarding the mouse event handler, which was really helpful, however, I need to stream these events out via socket.

Using http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Streams/Articles/PollingVersusRunloop.html#//apple_ref/doc/uid/20002275-CJBEDDBG

as as guide was helpful, but I have a disconnect with regard to intersecting the run-loop of the stream with the event handler loop.

All I really want is when I get a mouse move event, to spit it out of the socket. Do I even need a run-loop for the stream? If not, how do I do this??

Thanks for any input!

Chris

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:09:14+00:00Added an answer on May 15, 2026 at 3:09 pm

    All I really want is when I get a mouse move event, to spit it out of the socket.

    From the documentation you linked to:

    A potential problem with stream processing is blocking. A thread that is writing to … a stream might have to wait indefinitely until there is … space on the stream to put bytes….

    If you simply did a blocking write, you could block forever, hanging your application.

    If you simply did a non-blocking write, you may only write part of what you intended to. This will confuse the other side if you don’t remember what you have left and try to send it again later.

    Enter the run loop. Mouse-move events come in on the run loop, too—you don’t need or want a separate run loop. “Intersecting” the two sources of events is exactly what a run loop is for.

    You’ll want symmetry between your event handlers: Each should either send some bytes or remember some state (using a couple of instance variables for the latter).

    In the mouse-moved handler, if you have previously received a has-space-available event and did not have a mouse-moved event to send, send the one you just got. Otherwise, remember the event for later. (Keep only one event at a time—if you get another one, throw the older one away.)

    In the has-space-available handler, if you have a mouse-moved event that you have not sent, send it now. Otherwise, remember that you have space available, so you can use it at your next mouse-moved event.

    Either way, when you try to write the bytes and only write some of them, remember the bytes and where you left off. You should only start sending a new mouse-moved event after completely sending a previous one.

    Note that the solution as I have described it will drop events if you’re getting events faster than you can send them out. This is not a problem: If you’re getting them faster than you can send them out, and you keep them around until you can send them out, then either they will pile up and tip over (you run out of memory and your app crashes/your app stops working/you bog down the system) or the user will see instances of “catch-up” where the mouse on the receiving end slowly replays all the events as they slowly come in. I say it’s better, in your case, to drop events you couldn’t send and just let the receiving mouse teleport across space to make up the lost time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a JTable that has column spans available. Specifically, I
I'm trying to make a MFC application(client) that connects to a server on (localhost,port
I'm trying to make a little client-server script like many others that I've done
Trying to make a make generic select control that I can dynamically add elements
I'm trying to make a context menu for a control that is linked to
I am trying to make a div, that when you click it turns into
I am trying to write server that will communicate with any standard client that
Socket has a constructor that takes a winsock SOCKET as parameter and stores it
I am trying to make a simple game that goes across a TCP network.
I am trying to make a simple Client-Server application but when I execute the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.