C# socket ipv6初体验
Server:
serverSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); serverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); if (!string.IsNullOrEmpty(SocketBindingIP)) { serverSocket.Bind(new IPEndPoint(IPAddress.IPv6Any, int.Parse(Program.config.AppSettings.Settings["Middleware_PORT"].Value))); lbWebApiBaseAddress.Text = ip; LogMessage(DateTime.Now + "->Socket开启IPV6监听成功,监听IP:" + IPAddress.IPv6Any.ToString() + ":" + Program.config.AppSettings.Settings["Middleware_PORT"].Value); } else { serverSocket.Bind(new IPEndPoint(IPAddress.Parse(ip), int.Parse(Program.config.AppSettings.Settings["Middleware_PORT"].Value))); lbWebApiBaseAddress.Text = IPAddress.Parse(ip).ToString(); LogMessage(DateTime.Now + "->Socket开启IPV6监听成功,监听IP:" + IPAddress.Parse(ip) + ":" + Program.config.AppSettings.Settings["Middleware_PORT"].Value); }
client:
m_clientSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); m_clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); EndPoint ipeh_Server = new IPEndPoint(IPAddress.Parse(textBox1.Text), Convert.ToInt32(textBox2.Text)); if (!m_clientSocket.IsBound) { if (comboBox1.Text == "自动分配") { m_clientSocket.Bind(new IPEndPoint(IPAddress.IPv6Any, 0)); } else { m_clientSocket.Bind(new IPEndPoint(IPAddress.IPv6Any, Convert.ToInt32(comboBox1.Text))); } }
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"作者:" 数据酷软件工作室
"出处:" http://datacool.cnblogs.com
"专注于CMS(综合赋码系统),MES,WCS(智能仓储设备控制系统),WMS,商超,桑拿、餐饮、客房、足浴等行业收银系统的开发,15年+从业经验。因为专业,所以出色。"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"作者:" 数据酷软件工作室
"出处:" http://datacool.cnblogs.com
"专注于CMS(综合赋码系统),MES,WCS(智能仓储设备控制系统),WMS,商超,桑拿、餐饮、客房、足浴等行业收银系统的开发,15年+从业经验。因为专业,所以出色。"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++