sp; Private Sub StartChatting()
Dim RemoteHost As String = Dns.GetHostName
Dim RemotePort As Integer = 1984
Dim RemotePoint As IPEndPoint
Dim ready As Boolean = False
Dim msg As String
While Not ready ''''向用户询问发送消息的目标主机和端口。用户可以直接回车,表示选择默认的。
msg = GetParams("---enter the name of the one you want to chat with(" & RemoteHost & "):")
If Not msg = "" Then RemoteHost = msg
msg = GetParams("---enter the port number that guy listening at(" & RemotePort & "):")
If msg = "" Then msg = RemotePort
Try
RemotePort = Int(msg)
RemotePoint = New IPEndPoint(Dns.GetHostByName(RemoteHost).AddressList(0), RemotePort)
ready = True
Catch ex As Exception
Console.WriteLine("※※※ERROR※※※ " & vbCrLf & ex.Message & vbCrLf)
End Try
End While
Console.WriteLine()
Console.WriteLine("OK, now you can chat. Type ""help"" to find out what you can do.")
Console.WriteLine()
Dim sender As New UdpClient
Dim Message As String = Prompt()
While True ''''用户现在可以开始发送消息
Prompted = False
Select Case Message.ToLower
Case "exit"
Exit While
Case "help"
ShowHelp()
Case Else
Dim ByArr As Byte() = Encoding.Unicode.GetBytes(Message)
sender.Send(ByArr, ByArr.Length, RemotePoint) ''''发出消息
End Select
Message = Prompt()
End While
tListener.Abort()
End
End Sub
Private Function GetParams(ByVal Msg As String) As String
Console.Write(Msg)
Return Console.ReadLine
上一页 [1] [2] [3] 下一页 [Delphi程序]udp 500 D.O.S攻击 [VB.NET程序]如何用vb的winsocket解决udp文件传送丢包的问题 [JAVA开发]基于Java的UDP协议程序设计初探
|