Dim th As Threading.Thread
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供茌平網(wǎng)站建設(shè)、茌平做網(wǎng)站、茌平網(wǎng)站設(shè)計(jì)、茌平網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、茌平企業(yè)網(wǎng)站模板建站服務(wù),10多年茌平做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
2 Dim tcpl As System.Net.Sockets.TcpListener
3
4 Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5 th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6 th.Start()
7 End Sub
8
9 Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10 Try
11 If IP "" Then
12 Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13 Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14 Dim reqStream As New IO.StreamWriter(tcpStream)
15 reqStream.Write(SendMsg)
16 reqStream.Flush()
17 tcpStream.Close()
18 tcpc.Close()
19 End If
20 Catch ex As Exception
21 MsgBox(ex.Message.ToString)
22 End Try
23 End Sub
24 Private Sub MyListen()Sub MyListen()
25 Try
26 Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27 tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28 tcpl.Start()
29 While True
30 Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31 Dim MyBuffer(1024) As Byte
32 Dim i As Integer
33 i = s.Receive(MyBuffer)
34 If i 0 Then
35 Dim lstrRec As String
36 Dim j As Integer
37 For j = 0 To i - 1
38 TextBox1.Text += Chr(MyBuffer(j)) ","
39 Next
40 End If
41 End While
42 Catch ex As Exception
43 MsgBox(ex.Message.ToString)
44 End Try
45 End Sub
46
47 Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48 SendMessage("192.168.0.61", TextBox2.Text)
49 End Sub
做exe程序獲取本機(jī)IP地址用
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList
做web程序獲取客戶端的IP地址用
HttpContext.Current.Request.ServerVariables("REMOTE_ADDR"])
你最好可以換臺(tái)電腦訪問(wèn)網(wǎng)址看獲取IP地址狀況。
如果你測(cè)試訪問(wèn)的時(shí)候,使用的是 localhost 進(jìn)行訪問(wèn)的,那么服務(wù)器端獲得的也就是127.0.0.1,因?yàn)閘ocalhost是一個(gè)環(huán)路地址,特殊的.如果你是通過(guò)你的ip地址進(jìn)行訪問(wèn)的,那么獲得的IP地址就會(huì)是正確的了. 要通過(guò)自己本地的IP進(jìn)行訪問(wèn),在控制面板的網(wǎng)絡(luò)連接里找到本地連接,查看它的屬性,并找到"詳細(xì)信息"按鈕,點(diǎn)擊后彈出的對(duì)話框中IPV4地址就是本地地址.或打開(kāi)命令行,輸入 ipconfig /all 即可找到本地地址.在瀏覽器中通過(guò)這個(gè)IP地址訪問(wèn),就不會(huì)是127.0.0.1了.
1.獲取當(dāng)前電腦名:System.Net.Dns.GetHostName()
2.根據(jù)電腦名取出全部IP地址:System.Net.Dns.Resolve(電腦名).AddressList
或者 System.Net.Dns.GetHostByName(電腦名).AddressList
3.根據(jù)IP地址取出電腦名:System.Net.Dns.Resolve(IP地址).HostName
當(dāng)前標(biāo)題:vb.netip設(shè)置的簡(jiǎn)單介紹
鏈接URL:http://m.rwnh.cn/article16/hiisgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、面包屑導(dǎo)航、網(wǎng)站營(yíng)銷、外貿(mào)網(wǎng)站建設(shè)、企業(yè)建站、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)