I try to communicate using a simple TCP client server on UWP, I followed this link UWP socket but it looks like it doesn't works. I've added capabilities for both app to provide client & server. Even if it doesn't appear in the code, I have handled the error, which give me the following : System.Runtime.InteropServices.COMException (0x8007274C): A connection attemps has failed because the connected part has not answer after a certain amount of time or the connection has failed because host has not respond
System.Runtime.InteropServices.COMException (0x8007274C): Une tentative de connexion a échoué car le parti connecté n’a pas répondu convenablement au-delà d’une certaine durée ou une connexion établie a échoué car l’hôte de connexion n’a pas répondu.
As far I can look, it fails at the line await clientSocket.ConnectAsync(serverHost, serverPort);
At term, it should run the server on a Rasperry Pi 3 and the Client on a Windows 10 mobile (Lumia 950 XL build 14385) but until now I only terted on a surface pro 3 running Windows 10 Pro (build 14385)
Client
try
{
StreamSocket clientSocket;
clientSocket = new StreamSocket();
HostName serverHost = new HostName("localhost");
string serverPort = "5464";
await clientSocket.ConnectAsync(serverHost, serverPort);
Stream streamOut = clientSoket.OutputStream.AsStreamForWrite();
StreamWriter writer = new StreamWriter(streamOut);
string request = "test";
await writer.WriteLineAsync(request);
await writer.FlushAsync();
Stream streamIn = clientSocket.InputStream.AsStreamForRead();
StreamReader reader = new StreamReader(streamIn);
string response = await reader.ReadLineAsync();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());//handle
}
Server
try
{
serverSocket = new StreamSocketListener();
serverSocket.ConnectionReceived += ServerSocket_ConnectionReceived;
await serverSocket.BindServiceNameAsync("5464");
}
catch(Exception e)
{
Console.WriteLine(e.ToString());//handle
}
private async void ServerSocket_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
Stream inputStream = args.Socket.InputStream.AsStreamForRead();
StreamReader reader = new StreamReader(inputStream);
string request = await reader.ReadLineAsync();
Stream outputStream = args.Socket.OutputStream.AsStreamForWrite();
StreamWriter writter = new StreamWriter(outputStream);
await writter.WriteLineAsync("Ok");
await writter.FlushAsync();
}