如何使用 C# 从端口 9999 打开应用程序

How can I open application using C# from port 9999

我想使用 C# 代码打开应用程序。应用程序需要在端口号 9999 上打开。我不知道该怎么做。

谢谢。

你可以试试这个

  private void SendToServer(IPAddress IP, int Port) {
        try {
            TcpClient tcpclnt = new TcpClient();
            tcpclnt.Connect(IP, Port);
            //your code here
            }

UPDATE For the server you'll use this

public static void Main() {
            TcpListener serverSocket = new TcpListener(9999);
            TcpClient clientSocket = default(TcpClient);
            int counter = 0;
            serverSocket.Start();
            Console.WriteLine(" >> " + "Server Started");
            counter = 0;
            while (true) {
                counter += 1;
                clientSocket = serverSocket.AcceptTcpClient();
                Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
                handleClient client = new handleClient();
                client.startClient(clientSocket, Convert.ToString(counter));
            }

            clientSocket.Close();
            serverSocket.Stop();
            Console.WriteLine(" >> " + "exit");
            Console.ReadLine();
        }
    }

    public class handleClient {
//yourcodehere
}

Source