tcpclient发送的数据包未到达目的地

时间:2013-02-06 18:46:18

标签: vb.net tcpclient networkstream

我正在尝试使用tcpclient将消息发送到具有提供端口的远程服务器。在我的代码中,我看到连接成功并且正在发送消息但是另一端的开发人员通知我没有收到任何消息。有没有调试这个?

 Public Sub New(ip As String, port As Integer)
    _GLOIP = IPAddress.Parse(ip)
    _port = port
    'initiate the client and get the stream to use
    myTcp = initiate()
    netStream = myTcp.GetStream()
End Sub
Public Sub send(text As String, ByRef err As String)
    If netStream.CanWrite Then
        If Not text.EndsWith(vbCr & vbLf) Then
            text += Environment.NewLine
        End If
        Dim sendBytes As Byte() = Encoding.UTF8.GetBytes(text)
        netStream.Write(sendBytes, 0, sendBytes.Length)
    Else
        err = "cannot write to the stream"
    End If
End Sub
Public Function initiate() As TcpClient
    Dim TcpClient As New TcpClient()
    Dim bytCommand As Byte() = New Byte(1023) {}
    TcpClient.Connect(_GLOIP, _port)
    Return TcpClient
End Function

0 个答案:

没有答案