コード例 #1
0
 /// <summary>
 /// Determines if the client is connected to the peer server.
 /// </summary>
 /// <returns>True if connected.</returns>
 public bool IsConnected()
 {
     if (Wtcp == null)
     {
         if (Debug)
         {
             Console.WriteLine("Client object is null");
         }
         return(false);
     }
     return(Wtcp.IsConnected());
 }
コード例 #2
0
ファイル: APIConnect.cs プロジェクト: Pandawan/EasyGarlic
        public void TSendRequest(APIConnect.Request request)
        {
            logger.Warn("Sending request " + request);

            logger.Warn("Is client connected? " + client.IsConnected());

            // If client isn't connected, no point in trying to send
            if (!client.IsConnected())
            {
                logger.Warn("Could not send request. Client is not connected.");
                return;
            }

            bool val = client.Send(Encoding.ASCII.GetBytes(request.command));

            logger.Warn("Output " + val);
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: mihaly044/parkplaces
 public bool IsConnected()
 {
     return(_watsonTcpClient != null && _watsonTcpClient.IsConnected());
 }
コード例 #4
0
ファイル: TestClient.cs プロジェクト: zli69/WatsonTcp
        static void Main(string[] args)
        {
            Console.Write("Server IP    : ");
            serverIp = Console.ReadLine();

            Console.Write("Server Port  : ");
            serverPort = Convert.ToInt32(Console.ReadLine());

            WatsonTcpClient client = new WatsonTcpClient(serverIp, serverPort, ServerConnected, ServerDisconnected, MessageReceived, true);

            bool runForever = true;

            while (runForever)
            {
                Console.Write("Command [? for help]: ");
                string userInput = Console.ReadLine();
                if (String.IsNullOrEmpty(userInput))
                {
                    continue;
                }

                switch (userInput)
                {
                case "?":
                    Console.WriteLine("Available commands:");
                    Console.WriteLine("  ?          help (this menu)");
                    Console.WriteLine("  q          quit");
                    Console.WriteLine("  cls        clear screen");
                    Console.WriteLine("  send       send message to server");
                    Console.WriteLine("  sendasync  send message to server asynchronously");
                    Console.WriteLine("  status     show if client connected");
                    Console.WriteLine("  dispose    dispose of the connection");
                    Console.WriteLine("  connect    connect to the server if not connected");
                    Console.WriteLine("  reconnect  disconnect if connected, then reconnect");
                    break;

                case "q":
                    runForever = false;
                    break;

                case "cls":
                    Console.Clear();
                    break;

                case "send":
                    Console.Write("Data: ");
                    userInput = Console.ReadLine();
                    if (String.IsNullOrEmpty(userInput))
                    {
                        break;
                    }

                    client.Send(Encoding.UTF8.GetBytes(userInput));
                    break;

                case "sendasync":
                    Console.Write("Data: ");
                    userInput = Console.ReadLine();
                    if (String.IsNullOrEmpty(userInput))
                    {
                        break;
                    }

                    client.SendAsync(Encoding.UTF8.GetBytes(userInput));
                    break;

                case "status":
                    if (client == null)
                    {
                        Console.WriteLine("Connected: False (null)");
                    }
                    else
                    {
                        Console.WriteLine("Connected: " + client.IsConnected());
                    }

                    break;

                case "dispose":
                    client.Dispose();
                    break;

                case "connect":
                    if (client != null && client.IsConnected())
                    {
                        Console.WriteLine("Already connected");
                    }
                    else
                    {
                        client = new WatsonTcpClient(serverIp, serverPort, ServerConnected, ServerDisconnected, MessageReceived, true);
                    }
                    break;

                case "reconnect":
                    if (client != null)
                    {
                        client.Dispose();
                    }

                    client = new WatsonTcpClient(serverIp, serverPort, ServerConnected, ServerDisconnected, MessageReceived, true);
                    break;

                default:
                    break;
                }
            }
        }