Ejemplo n.º 1
0
 public void startListeningCallBack(IAsyncResult ar)
 {
     try
     {
         AsyncNetworkConnectorServer connector = (AsyncNetworkConnectorServer)ar.AsyncState;
         FlaggedSocket tempSocket = new FlaggedSocket();
         tempSocket.socket = (connector.listenerSocket.EndAccept(ar));
         connector.connectedClientList.Add(tempSocket);
         Console.WriteLine("Added socket to client list");
         connector.listenerSocket.BeginAccept(new AsyncCallback(startListeningCallBack), connector);
     }
     catch (Exception e)
     {
         Console.WriteLine("Error in startListeningCallBack: " + e.ToString());
     }
 }
Ejemplo n.º 2
0
 public void sendCallBack(IAsyncResult ar)
 {
     try
     {
         FlaggedSocket tempSocket = (FlaggedSocket)ar.AsyncState;
         if (tempSocket.socket.Connected)
         {
             int sentBytes = tempSocket.socket.EndSend(ar);
             Console.WriteLine("Number of Bytes sent = " + sentBytes.ToString());
             tempSocket.prevSendDoneFlag = true;
         }
     }
     catch (Exception e)
     {
         FlaggedSocket tempSocket = (FlaggedSocket)ar.AsyncState;
         Console.WriteLine("Error in sendCallBack: " + e.ToString());
         tempSocket.socket.Close();
         tempSocket.socket.Dispose();
         this.connectedClientList.Remove(tempSocket);
     }
 }
Ejemplo n.º 3
0
 public void send(FlaggedSocket tempSocket, byte[] data)
 {
     try
     {
         if (tempSocket.prevSendDoneFlag)
         {
             tempSocket.prevSendDoneFlag = false;
             tempSocket.socket.BeginSend(data, 0, data.Length, 0, new AsyncCallback(this.sendCallBack), tempSocket);
         }
         else
         {
             Console.WriteLine("Skipping");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error in send: " + e.ToString());
         tempSocket.socket.Close();
         tempSocket.socket.Dispose();
         this.connectedClientList.Remove(tempSocket);
     }
 }
Ejemplo n.º 4
0
        public void send(FlaggedSocket tempSocket, byte[] data)
        {
            try
            {
                if (tempSocket.prevSendDoneFlag)
                {
                    tempSocket.prevSendDoneFlag = false;
                    tempSocket.socket.BeginSend(data, 0, data.Length, 0, new AsyncCallback(this.sendCallBack), tempSocket);
                }
                else
                {
                    Console.WriteLine("Skipping");
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("Error in send: " + e.ToString());
                tempSocket.socket.Close();
                tempSocket.socket.Dispose();
                this.connectedClientList.Remove(tempSocket);
            }
        }
Ejemplo n.º 5
0
 public void startListeningCallBack(IAsyncResult ar)
 {
     try
     {
         AsyncNetworkConnectorServer connector = (AsyncNetworkConnectorServer)ar.AsyncState;
         FlaggedSocket tempSocket = new FlaggedSocket();
         tempSocket.socket = (connector.listenerSocket.EndAccept(ar));
         connector.connectedClientList.Add(tempSocket);
         Console.WriteLine("Added socket to client list");
         connector.listenerSocket.BeginAccept(new AsyncCallback(startListeningCallBack), connector);
     }
     catch (Exception e)
     {
         Console.WriteLine("Error in startListeningCallBack: " + e.ToString());
     }
 }