예제 #1
0
 public static void Disconnect()
 {
     TCP.Close();
     TCP.Dispose();
     TCP      = null;
     listener = null;
 }
예제 #2
0
파일: IrcClient.cs 프로젝트: DoubleGG/hsbot
 /// <summary>
 /// Disconnects client and disposes of streams. Also stops timeout-check timer.
 /// </summary>
 public void Disconnect()
 {
     lock (_registrationLock)
     {
         Connected  = false;
         Registered = false;
         if (TCP != null && TCP.Connected)
         {
             try
             {
                 TCP.Close();
                 streamReader.Dispose();
                 streamWriter.Dispose();
             }
             catch (Exception) { } // Eat exceptions since this is just an attempt to clean up
         }
     }
     lock (timeoutTimer)
     {
         timeoutTimer.Dispose();
         timeoutTimer          = new System.Timers.Timer(Timeout.TotalMilliseconds);
         timeoutTimer.Elapsed += TimeoutTimerElapsedHandler;
         timeoutTimer.Start();
     }
     lock (pingTimer)
     {
         pingTimer.Dispose();
         pingTimer          = new System.Timers.Timer(Timeout.TotalMilliseconds / 2);
         pingTimer.Elapsed += (sender, args) => { var task = SendRawMessage("PING :LRTIRC"); };
         pingTimer.Start();
     }
 }
        protected override void CloseSocket()
        {
            base.CloseSocket();
            if (TCP.Connected)
            {
                TCP.Client.Shutdown(SocketShutdown.Both);
            }
            TCP.Client.Close();

            //TODO
            TCP.Close();
        }
예제 #4
0
 /// <summary>
 /// 通信を切断します。
 /// </summary>
 private void DisConnect()
 {
     if (Stream != null)
     {
         Stream.Dispose();
         Stream = null;
     }
     if (TCP != null)
     {
         TCP.Close();
         TCP = null;
     }
 }
예제 #5
0
        private async void Escutando(object obj)
        {
            Byte[] data = new Byte[1024 * 8];
            while (App.Conversando)
            {
                String responseData = String.Empty;
                Int32  bytes        = await Stream.ReadAsync(data, 0, data.Length);

                responseData = System.Text.Encoding.UTF8.GetString(data, 0, bytes);
                var label = AddLabel(Color.Blue, responseData);
                Device.BeginInvokeOnMainThread(async() =>
                {
                    stack.Children.Add(label);
                    await scroll.ScrollToAsync(stack, ScrollToPosition.End, false);
                });
            }
            TCP.Close();
        }
예제 #6
0
        // Desconecta cliente TCP
        public bool Disconnect()
        {
            //
            StopReceive();
            //Fecha cliente
            TCP.Close();

            if (!TCP.Connected)
            {
                // Chama evento informando que foi desconectado!
                OnDisconnectEvent(new EventArgs());
                // Desconectado com sucesso
                return(true);
            }
            else
            {
                // Desconexão falhou.
                return(false);
            }
        }
예제 #7
0
        private static unsafe void HttpTest()
        {
            TCPConnection con = TCP.Bind(80);

            string message  = "<!doctype html><html><title>Van Sharpen</title><body>Wij serveren dit van Sharpen naar Dossche</body></html>";
            string httpResp = "HTTP/1.1 200 OK\r\nDate: Fri, 13 May 2005 05:51:12 GMT\r\nServer: Sharpen :)\r\nLast-Modified: Fri, 13 May 2005 05:25:02 GMT\r\nAccept-Ranges: bytes\r\nContent-Length: ";

            string count = message.Length.ToString();

            httpResp = String.Merge(httpResp, count);
            httpResp = String.Merge(httpResp, "\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n");

            string finalResp = String.Merge(httpResp, message);

            TCPPacketDescriptor *ptr;

            while (true)
            {
                ptr = TCP.Read(con);
                if (ptr == null)
                {
                    continue;
                }

                if (ptr->Type == TCPPacketDescriptorTypes.ACCEPT)
                {
                    Console.Write("New connection from: ");
                    for (int i = 0; i < 3; i++)
                    {
                        Console.WriteNum(ptr->Data[i]);
                        Console.Write('.');
                    }
                    Console.WriteNum(ptr->Data[3]);
                    Console.Write(" with XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.RECEIVE)
                {
                    Console.Write("New data from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");

                    TCP.Send(con, ptr->xid, (byte *)Util.ObjectToVoidPtr(finalResp), (uint)finalResp.Length);

                    TCP.Close(con, ptr->xid);
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.RESET)
                {
                    Console.Write("RESET from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else if (ptr->Type == TCPPacketDescriptorTypes.CLOSE)
                {
                    Console.Write("CLOSE from XID: ");
                    Console.WriteHex(ptr->xid);
                    Console.WriteLine("");
                }
                else
                {
                    Console.WriteLine("Invalid ptr->Type!");
                    break;
                }

                Heap.Free(ptr);
            }

            Console.WriteLine("EXIAT");
            for (;;)
            {
                ;
            }

            TCP.Free(con);
        }
예제 #8
0
 public void DoneSending()
 {
     tcpSession.Close();
     state = State.Closed;
 }