[Fix] Bracket it if IPv6 address

Fix for a part of pull request #264.
This commit is contained in:
sta 2016-05-27 16:11:34 +09:00
parent e8661442a8
commit 5885971f90

View File

@ -630,9 +630,17 @@ namespace WebSocketSharp.Server
return !(usr || port) ? "The secure connection requires a server certificate." : null; return !(usr || port) ? "The secure connection requires a server certificate." : null;
} }
private static string convertToString (System.Net.IPAddress address)
{
var str = address.ToString ();
return address.AddressFamily == AddressFamily.InterNetworkV6
? String.Format ("[{0}]", str)
: str;
}
private void init (string hostname, System.Net.IPAddress address, int port, bool secure) private void init (string hostname, System.Net.IPAddress address, int port, bool secure)
{ {
_hostname = hostname ?? address.ToString (); _hostname = hostname ?? convertToString (address);
_address = address; _address = address;
_port = port; _port = port;
_secure = secure; _secure = secure;