Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 5th, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Periodically send data from server to clients
  2. public void AcceptCallback(IAsyncResult ar)
  3.     {
  4.         allDone.Set(); // Signal the main thread to continue.
  5.  
  6.         // Get the socket that handles the client request.
  7.         Socket listener = (Socket)ar.AsyncState;
  8.         Socket handler = listener.EndAccept(ar);
  9.         IPEndPoint remotePoint = (IPEndPoint)handler.RemoteEndPoint;
  10.         IPAddress remoteAddress = remotePoint.Address;
  11.         Console.WriteLine("Connected to {0}!", remoteAddress.ToString());
  12.  
  13.         // Create the state object.
  14.         StateObject state = new StateObject();
  15.         state.workSocket = handler;
  16.  
  17.         //Start periodically sending here??
  18.  
  19.         handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
  20.             new AsyncCallback(ReadCallback), state);
  21.     }