Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Can't establish Socket connection

$
0
0

Hi,

I am using @RyanDavis 's sockets-to-pcl plugin in a xamarin.form project.
I am following the tcpSocketClient sample code posted in the GitHub repository https://github.com/rdavisau/sockets-for-pcl but I can not make the tcpSocketClientto connect to a tcpSocketListener.

I create a class that just connect to the ip and port of a socket client server, when I debug the code I get an exception telling that it is from external code, this is the code:

public async void Connect()
        {
            var address = "201.217.142.42";
            var port = 7960;
            var r = new Random();
            var client = new TcpSocketClient();
            await client.ConnectAsync(address, port);
            // we're connected!
            for (int i = 0; i < 5; i++)
            {
                // write to the 'WriteStream' property of the socket client to send data
                var nextByte = (byte)r.Next(0, 254);
                client.WriteStream.WriteByte(nextByte);
                await client.WriteStream.FlushAsync();
                // wait a little before sending the next bit of data
                await Task.Delay(TimeSpan.FromMilliseconds(500));
            }
            await client.DisconnectAsync();
        }

Any ideas of what can be happening?
Thanks for any help


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>