Hi fellow programmers,
I am new to UWP so would like to thank you in advance for helping me on this issue.
I am following this MSDN article of "How to create and use a TCP socket client app for Windows Phone 8"
https://msdn.microsoft.com/en-us/library/windows/apps/hh202858(v=vs.105).aspx[
^]
in VS 2015 to test how the
System.Net.Sockets.Socket
Class works in UWP app.
I basically ported the whole project into an UWP application and it works as expected with the built-in Simple TCP/IP Services on my computer.
However, as soon as I changed the IP and port number to an existing TCP socket server on my LAN (IP: 192.168.200.254, Port: 2223) I get AccessDenied Exception on connecting.
Here is the code for Connect():
public string Connect(string hostName, int portNumber)
{
string result = string.Empty;
DnsEndPoint hostEntry = new DnsEndPoint(hostName, portNumber);
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = hostEntry;
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate (object s, SocketAsyncEventArgs e)
{
result = e.SocketError.ToString();
_clientDone.Set();
});
_clientDone.Reset();
_socket.ConnectAsync(socketEventArg);
_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
return result;
}
I tried different non-existence ip and ports, always get the same exception. So looks like a client side issue. The call has never got to the server.
Do I need to do any additional settings on my client side code?
There is another issue when porting this code to UWP:
The Socket.Close() method is no longer there!?
The closest is ShutDown().
Is this ShutDown() supposed to be the replacement?
Kind regards.