Hi ich hab hier nen chat und mein Problem ist das die anwendung nicht gestartet wird ich bekomme immer den Fehler das der Zielcomputer den zugriff verweigert was kann ich da tun ??
Server
client
Server
VB.NET-Quellcode
- Imports System.Net.Sockets
- Imports System.Text
- Public Class Form1
- Private SimpleServer As TcpListener
- Private Client As New TcpClient
- Private Stream As NetworkStream
- Dim bytes() As Byte
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- SimpleServer = New TcpListener(System.Net.IPAddress.Parse(0), 12345)
- SimpleServer.Start()
- SimpleServer.BeginAcceptTcpClient(AddressOf OnConnect, New Object)
- End Sub
- Private Sub OnConnect(ByVal ar As System.IAsyncResult)
- Client = SimpleServer.EndAcceptTcpClient(ar)
- Stream = Client.GetStream
- ReDim bytes(Client.ReceiveBufferSize)
- Stream.BeginRead(bytes, 0, CInt(Client.ReceiveBufferSize), AddressOf onGetData, New Object)
- End Sub
- Private Sub onGetData(ByVal ar As System.IAsyncResult)
- Dim clientdata As String = Encoding.ASCII.GetString(bytes)
- MsgBox(clientdata)
- Stream.BeginRead(bytes, 0, CInt(Client.ReceiveBufferSize), AddressOf onGetData, New Object)
- End Sub
- End Class
client
VB.NET-Quellcode
- Imports System.Net.Sockets
- Imports System.Text
- Public Class Form2
- Private SimpleClient As New TcpClient
- Private Stream As NetworkStream
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- SimpleClient.Connect("192.168.2.1", 12345)
- Stream = SimpleClient.GetStream
- TextBox2.Text = Stream.ToString
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(textbox1.text)
- Stream.Write(sendBytes, 0, sendBytes.Length)
- End Sub
- End Class