创建一个可以在两台计算机之间传递构建字符串的程序。
在挖掘和更改语法之后,我终于能够看到这个套接字异常:
System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address (protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.Net.Sockets.TcpListener.Start(Int32 backlog)
at System.Net.Sockets.TcpListener.Start()
at ChatProgFinal.chatForm.serverMode()
我使用的端口是 11337。根据 netstat,我没有使用那个端口,所以我不确定我还能如何抛出这个异常。
这是我的 serverMode 块:
Public Sub serverMode()
Try
Dim server As TcpListener = Nothing
server = New TcpListener(LocalIPEndPointAnyIP)
server.Start()
Dim incomingClient As TcpClient = server.AcceptTcpClient()
Do While isAlive = True And incomingClient.Connected = True
stream = incomingClient.GetStream()
If stream.CanRead Then
RaiseEvent DataReceived(stream)
End If
If incomingClient.Connected = False Then
RaiseEvent statusCheck("Disconnected")
isAlive = False
server.Stop()
End If
Loop
Catch e As Exception
RaiseEvent statusCheck(e.ToString)
Using outfile As New StreamWriter(docPath + "\log.txt")
outfile.Write(e.ToString)
End Using
Finally
stream.Close()
End Try
End Sub
感谢您对此提供的任何建议。附带问题:我不确定如何测试/调试通过 Visual Studio 2010 在两台计算机之间进行通信的软件。我现在正在做的是发布它并部署到测试 VM。有人有我可以使用的其他方法吗?