以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- TCPIP通讯获取客户端IP地址 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=132917) |
-- 作者:mayazql -- 发布时间:2019/4/2 11:17:00 -- TCPIP通讯获取客户端IP地址 学习TCPIP通讯,下面是服务端代码,想获取客户端IP地址,语句不知道怎么写,请教下老师。谢谢! Public Sserver As System.Net.Sockets.Socket Public Sub getData() Dim ip As String = forms("窗口1").Controls("ip").text Dim duankou As String = forms("窗口1").Controls("duankou").text Sserver = New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp) Dim LocalEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), duankou) Sserver.Bind(localEndPoint) Sserver.Listen(1000) Do While True Dim newsocket As System.Net.Sockets.Socket = Sserver.Accept() Dim bytes(1024) As Byte Dim data As String = String.Empty Dim bytesRec As Integer = newsocket.Receive(bytes) data = Encoding.default.GetString(bytes, 0, bytesRec) Forms("窗口1").Controls("neirong").text = data Forms("窗口1").Controls("Label3").text = (newsocket.RemoteEndPoint As IPEndPoint).IPAddress.ToString() ----获取客户端IP地址 newsocket.Close() Loop End Sub |
-- 作者:有点甜 -- 发布时间:2019/4/2 11:54:00 -- newsocket.RemoteEndPoint.Address.ToString
https://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.remoteendpoint(VS.80).aspx |
-- 作者:mayazql -- 发布时间:2019/4/2 15:24:00 -- 甜老师,你好,系统报错,说:编译错误:“Address”不是“System.Net.EndPoint”的成员 麻烦再帮忙看下。谢谢
|
-- 作者:有点甜 -- 发布时间:2019/4/2 15:54:00 -- Dim abc = newsocket.RemoteEndPoint msgbox(abc.Address.ToString) |
-- 作者:mayazql -- 发布时间:2019/4/2 20:57:00 -- 谢谢甜老师,这样可以了。 |