想写一个局域网聊天系统
没有写过,请问谁有这方面的经验或实例,要能传送附件的,请哪位好心个讲解一下思路或上传一个实例看看?小女子谢谢大家啦!
Const Bs = "~UDP~" '通讯联络开始标识 Private Sub Command1_Click() If Trim(Text2) <> "" Then Wsck.SendData Bs & "3" & Trim(Text2) Text1 = Text1 & Time & " 你对" & Wsck.RemoteHostIP & "说:" & Text2 & vbCrLf End If End Sub Private Sub Form_Load() On Error GoTo err_CL Wsck.Protocol = sckUDPProtocol Combo1.Clear If SearchServer Then Exit Sub '找到服务器的处理 Wsck.LocalPort = 8888 Wsck.Bind Exit Sub err_CL: MsgBox "端口可能被占用,启动失败" Unload Me End Sub Private Function SearchServer() As Boolean '本过程扫描看有没有服务端等待通讯 Dim i As Integer, j As Integer, d As Date SearchServer = False Wsck.RemoteHost = "255.255.255.255" '广播地址 Wsck.RemotePort = 8888 Wsck.Bind For i = 0 To 4 '发10次广播信息 Wsck.SendData Bs & "1" '广播求服务器信息 d = Time While d = Time DoEvents Wend Next If Combo1.ListCount = 0 Then Combo1.AddItem "我是服务器" Combo1.Text = "我是服务器" Wsck.Close Else SearchServer = True Combo1 = Combo1.List(0) End If End Function Private Sub Wsck_DataArrival(ByVal bytesTotal As Long) Dim a As String, b() As String, i As Integer Wsck.GetData a, vbString b = Split(a, Bs): i = Val(Left(b(1), 1)) If i = 1 Then Wsck.SendData Bs & "2" & Wsck.LocalIP '数据1表明有客户连接,需向对方返回我的地址 If i = 2 Then Combo1.AddItem Right(b(1), Len(b(1)) - 1) '2表明是服务器送来的信息,将后面的ip都放进combo1中 If i = 3 Then Text1 = Text1 & Time & " " & Wsck.RemoteHostIP & "对你说:" & Right(b(1), Len(b(1)) - 1) & vbCrLf '聊天信息 End Sub