vb.net局域网广播 局域网的广播功能,具体怎么操作的?( 二 )


27tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28tcpl.Start()
29While True
30Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31Dim MyBuffer(1024) As Byte
32Dim i As Integer
33i = s.Receive(MyBuffer)
34If i0 Then
35Dim lstrRec As String
36Dim j As Integer
37For j = 0 To i - 1
38TextBox1.Text += Chr(MyBuffer(j))","
39Next
40End If
41End While
42Catch ex As Exception
43MsgBox(ex.Message.ToString)
44End Try
45End Sub
46
47Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48SendMessage("192.168.0.61", TextBox2.Text)
49End Sub
vb的UDP广播方案:
所有的CLIEN的WINSOCK全用控件数组 。
如:
CLIENT(0)
然后在要广播的时候
sub BroadCoast()
for I =0 to client.count-1
if client(i).state=7 then
client(i).senddata
end if
next
end sub
给你帖一个我的游戏服务器代码:
Private Sub Command1_Click()
Dim intI As Integer
For I = 0 To 最大人数
If Ws(I).State0 Then Ws(I).Close
Next
End
End Sub
Private Sub Command2_Click()
Dim TheIndex As Long
Dim Response
TheIndex = CLng(LsUser.ListIndex)
If TheIndex = -1 Then Exit Sub
Response = MsgBox("真的要把用户"用户(CInt(TheIndex)).用户名"删除下线吗?"TheIndex, vbOKCancel + vbQuestion)
If Response = vbOK Then
Dim KillReson As String
KillReson = InputBox("请输入踢用户下线的理由:", "踢用户下线", "")
If Len(KillReson) = 0 Then Exit Sub
FrmMain.Ws(TheIndex + 1).SendData Encrypt("444$"KillReson, LngKeyE, LngKeyD, LngKeyN)
DoEvents
'Call KillUser(CInt(TheIndex))
Else
Exit Sub
End If
End Sub
Private Sub Command3_Click()
Dim I, K As Long
For I = 0 To LsUser.ListCount - 1
'If Trim(LsUser.Text) = 用户(I + 1).用户名 And 用户(I + 1).用户状态 = 0 Then
' LsUser.RemoveItem I + 1
' End If
For K = 1 To 最大人数
If Trim(LsUser.List(I)) = 用户(K).用户名 And 用户(K).用户状态 = 0 Then
LsUser.RemoveItem CInt(用户(K).在线列表号)
End If
Next
Next
Labonline.Caption = "当前在线:"LsUser.ListCount"人"
End Sub
Private Sub Form_Load()
Dim I As Long
最大人数 = 5
当前连接号 = 1
For I = 2 To 最大人数
Load Ws(I)
DoEvents
Next
WsListen.LocalPort = "1982"
WsListen.Listen
DeBugs ("服务器已经准备就绪"vbCrLf"共加载个"最大人数"连接"vbCrLf"服务IP:"WsListen.LocalIPvbCrLf"端口:"WsListen.LocalPort)
Call ConnData
Me.Show
End Sub
Private Sub Form_Unload(Cancel As Integer)
For I = 1 To 最大人数
If Ws(I).State0 Then
Ws(I).Close
End If
Next
End Sub
Private Sub LsUser_Click()
Dim strTheU, Uindex() As String
strTheU = Trim(LsUser.Text)
strTheU = "用户名:"用户(CLng(LsUser.ListIndex + 1)).用户名vbCrLf
strTheU = strTheU"昵称:"用户(CLng(LsUser.ListIndex + 1)).昵称vbCrLf
strTheU = strTheU"积分:"用户(CLng(LsUser.ListIndex + 1)).积分vbCrLf
strTheU = strTheU"胜:"用户(CLng(LsUser.ListIndex + 1)).胜vbCrLf
strTheU = strTheU"败:"用户(CLng(LsUser.ListIndex + 1)).败vbCrLf
strTheU = strTheU"团 队:"用户(CLng(LsUser.ListIndex + 1)).团队名vbCrLf
strTheU = strTheU"职 务:"用户(CLng(LsUser.ListIndex + 1)).职务vbCrLf
strTheU = strTheU"IP:"用户(CLng(LsUser.ListIndex + 1)).IPvbCrLf
strTheU = strTheU"连接号:"用户(CLng(LsUser.ListIndex + 1)).连接号vbCrLf
strTheU = strTheU"用户状态:"用户(CLng(LsUser.ListIndex + 1)).用户状态vbCrLf

推荐阅读