vb.net拓扑寻路的简单介绍-成都快上网建站

vb.net拓扑寻路的简单介绍

怎样用VB.NET进行网络编程?

都可以,可以用winsock,也可以自己重写SOCKET套接字.建议你如果工期紧,可以先用WINSOCK.当然最好是自己学用SOCKET套接字.这对未来开发网络通讯是很有帮助的.因为用WINSOCK有个毛病就是杀毒软件总会阻止

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序设计、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了东乌珠穆沁免费建站欢迎大家使用!

用vb.net实现网络通信

用 vb.net socket通信

Dim th As Threading.Thread

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

用vb.netl编写的floyd算法求两点间的最短路径,怎么输出path经过的顶点序列?

Function Min(x() as integer,y() as integer) as double

dim i,j,k,a

dim m() as double

dim s() as string

dim mins as string

redim m(ubound(x),ubound(x))

redim s(ubound(x),ubound(x))

for i=1 to ubound(x)-1 '从起始点0点到i点的距离

m(i,0)=((x(i)-x(0))^2+(y(i)-y(0))^2)^0.5

s(i,0)="0-" cstr(i)

next

'从起始点开始经过K个点后到达i点的最短距离m(i,k),s为各点的连线如"0-3-2-1-4"

for k=1 to ubound(x)-2

for i=1 to ubound(x)-1

m(i,k)=10^307

for j=1 to ubound(x)-1

if instr(s(j,k-1),cstr(i))=0 then'避免重复走一点

a=((x(i)-x(j))^2+(y(i)-y(j))^2)^0.5

if a+m(j,k-1)m(i,k) then

m(i,k)=a+m(j,k-1)

s(i,k)=s(j,k-1) "-" cstr(i)

endif

end if

next

next

next

'计算经过各点后到达最后一个点的最短距离

min=10^307

for j=1 to ubound(x)-1

a=((x(ubound(x))-x(j))^2+(y(ubound(x))-y(j))^2)^0.5

if a+m(j,ubound(x)-2)min then

min=a+m(j,ubound(x)-2)

mins=s(j,ubound(x)-2) "-" cstr(ubound(x))

end if

next

msgbox "最短距离:" min vbcrlf "最短路径:" mins

End function

private sub Command1_Click

dim x(5) as integer

dim y(5) as integer

dim m as double

x(0)=0

y(0)=0

x(1)=40

y(1)=600

......

x(5)=1000

y(5)=1000

m=min(x,y)

End sub


本文名称:vb.net拓扑寻路的简单介绍
文章出自:http://kswjz.com/article/heehsi.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流