Hallo Leute,
versuche gerade eine Verbindung aufzubauen, jedes mal kommt der Fehler. Kann mir jemand helfen? (Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte (10061))
Beispiel von MS:
Danke im Voraus
versuche gerade eine Verbindung aufzubauen, jedes mal kommt der Fehler. Kann mir jemand helfen? (Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte (10061))
Beispiel von MS:
VB.NET-Quellcode
-
- Shared Sub Connect(ByVal serverIP As String, ByVal message As String)
- Dim output As String = ""
- Try
- ' Create a TcpClient.
- ' The client requires a TcpServer that is connected
- ' to the same address specified by the server and port
- ' combination.
- Dim port As Int32 = 10045
- Dim client As New TcpClient(serverIP, port)
- ' Translate the passed message into ASCII and store it as a byte array.
- Dim data(255) As [Byte]
- data = System.Text.Encoding.ASCII.GetBytes(message)
- ' Get a client stream for reading and writing.
- ' Stream stream = client.GetStream();
- Dim stream As NetworkStream = client.GetStream()
- ' Send the message to the connected TcpServer.
- stream.Write(data, 0, data.Length)
- output = "Sent: " + message
- MessageBox.Show(output)
- ' Buffer to store the response bytes.
- data = New [Byte](255) {}
- ' String to store the response ASCII representation.
- Dim responseData As String = String.Empty
- ' Read the first batch of the TcpServer response bytes.
- Dim bytes As Int32 = stream.Read(data, 0, data.Length)
- responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
- output = "Received: " + responseData
- MessageBox.Show(output)
- ' Close everything.
- stream.Close()
- client.Close()
- Catch e As ArgumentNullException
- output = "ArgumentNullException: " + e.ToString()
- MessageBox.Show(output)
- Catch e As SocketException
- output = "SocketException: " + e.ToString()
- MessageBox.Show(output)
- End Try
- End Sub
Danke im Voraus