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

TCP Socket Connection to External Device.

$
0
0

Hello,

I am currently developing an app that connects to a device that has an IP address and Port number. Traditionally I connect to these devices via PC using System.NET.Sockets. For some background the device gets a TCP message and it responds to a query sent by the PC. For the purposes of this project, I am required to use an Android system (I'm using Xamarin forms for future ports to windows mobile and iOS).

When using a windows desktop app to connect the code resembles something like this:

private string queryDEV (string query)
{
TcpClient = tcpClient = new TcpClient();
byte[] bytesSent = Encoding.Default.GetBytes (query);
byte[] bytesReceived = new byte[255];
NetworkStream networkStream = null;
string Reponse = "";
int bytes;

tcpClient.Connect(IP, port);

networkStream = tcpClient.GetStream();
networkStream.Write(bytesSent);


bytes = networkStream.Read(bytesReceived, 0, bytesReceived.ToString().Length);
Response = Reponse + Encoding.Default.GetString(bytesReceived, 0, bytes);

return Response;

}

Can anyone provide me an android sample version of this?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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