namespace Server_App
{
public partial class MainWindow : Window
{
public TcpListener server;
public Socket socket;
public NetworkStream ns;
public MainWindow()
{
InitializeComponent();
server = new TcpListener(8888);
server.Start();
}
private void btn_Click(object sender, RoutedEventArgs e)
{
socket = server.AcceptSocket();
ns = new NetworkStream(socket);
StreamReader sr = new StreamReader(ns);
tb.Text = sr.ReadLine();
ns.Flush();
ns.Close();
socket.Close();
}
}}
每当我从我的 android 手机发送消息时,它会在我单击按钮时在我的 serverapp 上接收。但是我想这样做,它有争议地接收我的消息,而无需每次都单击按钮。我尝试了 while(true) 语句,但我不知道它不起作用。记住它是 WPF serverapp 谁能帮助我?