我对编写控制台应用程序很陌生。我不明白为什么当控制台运行并写入它收到的消息时,它会在控制台中创建一堆额外的行。我敢肯定这是愚蠢的,但我在不得已的情况下,因为谷歌上没有人显然对 vb.net 如此愚蠢。提前致谢!
Sub Main()
Do
Console.WriteLine("Waiting for connection...")
server.Start()
client = server.AcceptTcpClient()
Console.WriteLine("Connected")
Do
stream = client.GetStream()
Dim recvBytes(client.ReceiveBufferSize) As Byte
stream.Read(recvBytes, 0, client.ReceiveBufferSize)
Dim recvText As String = Encoding.ASCII.GetString(recvBytes)
Console.WriteLine(recvText)
responses = Console.ReadLine
If responses = "close" Then
stream.Close()
client.Close()
server.Stop()
Environment.Exit(0)
Else
Dim sendBytes() As Byte = Encoding.ASCII.GetBytes(responses)
stream.Write(sendBytes, 0, sendBytes.Length)
Console.WriteLine("Message Sent")
End If
If client.Connected = False Then
Console.WriteLine("Client is no longer connected")
Exit Do
End If
Loop
Loop
End Sub