示例#1
0
 static void BeginAccept(OnConnected onConnected)
 {
     try
     {
         var state = new AcceptStateObject()
         {
             onConnected = onConnected
         };
         while (true)
         {
             // Set the event to nonsignaled state.
             allDone.Reset();
             // Start an asynchronous socket to listen for connections.
             Debug.Log("Waiting for a connection...");
             lock (socketLock)
             {
                 if (socket != null)
                 {
                     socket.BeginAccept(new AsyncCallback(AcceptCallback), state);
                 }
                 else
                 {
                     break;
                 }
             }
             // Wait until a connection is made before continuing.
             allDone.WaitOne();
         }
     }
     catch (Exception e)
     {
         Debug.LogError(e.ToString());
     }
     Debug.Log("Server stopped.");
 }
示例#2
0
 public SockMgrAcceptEventArgs(SockMgr handler, AcceptStateObject state, object externalCallbackState = null)
 {
     State = state; ExternalCallbackState = externalCallbackState; base.Handler = handler;
 }