我想使用c#代码打开应用程序。应用程序需要在端口号9999处打开。我不知道该怎么做。
谢谢。
答案 0 :(得分:0)
你可以试试这个
private void SendToServer(IPAddress IP, int Port) {
try {
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect(IP, Port);
//your code here
}
UPDATE 对于服务器,您将使用此
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
}