与Xamarin Android的Xamarin TCP套接字连接PC

时间:2017-04-02 00:43:35

标签: c# sockets xamarin xamarin.android xamarin.forms

我在Xamarin Android中构建远程应用程序,我遇到了连接问题。 错误:System.Net.Sockets.SocketException:没有到主机的路由。

Client :-
Button con = FindViewById<Button>(Resource.Id.btnConnect);
        var ip = FindViewById<EditText>(Resource.Id.txtIP);
        var port = FindViewById<EditText>(Resource.Id.txtPort);
        var show = FindViewById<EditText>(Resource.Id.txtShow);
        var view = FindViewById<ImageView>(Resource.Id.imageView);
        show.Text = ip_address("");
    con.Click += delegate
        {
            IPEndPoint point = new 
IPEndPoint(IPAddress.Parse(ip.Text),int.Parse(port.Text));
            TcpClient client = new TcpClient();
            client.Connect(point);
            show.Text = "Connected";
        };

Server:-
TcpListener listen = new TcpListener(IPAddress.Any, 5656);
            listen.Start();
            Socket sc = listen.AcceptSocket();
            MessageBox.Show("Connected");
Button con = FindViewById<Button>(Resource.Id.btnConnect);
        var ip = FindViewById<EditText>(Resource.Id.txtIP);
        var port = FindViewById<EditText>(Resource.Id.txtPort);
        var show = FindViewById<EditText>(Resource.Id.txtShow);
        var view = FindViewById<ImageView>(Resource.Id.imageView);
        show.Text = ip_address("");
    con.Click += delegate
        {
            IPEndPoint point = new 
IPEndPoint(IPAddress.Parse(ip.Text),int.Parse(port.Text));
            TcpClient client = new TcpClient();
            client.Connect(point);
            show.Text = "Connected";
        };

0 个答案:

没有答案