I'm trying to create a messenger-like program, which user will enter an IP adress and connect to another user and send messages with a send button, and receive and view messages at a textbox. But my problem: "The target machine actively refused". I'm trying to connect myself for testing using 127.0.0.1, what is wrong at this?
Imports System.IO
Imports System.Threading
Imports System.Net.Sockets
Public Class datsend
Public dinleyici As New TcpListener(33333)
Dim client As New TcpClient
Dim msg As String = ""
Private Sub calis_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calis.Click
If Val(port.Text) = 0 Then
MsgBox("Port missing!")
ElseIf Val(IP.Text) = 0 Then
MsgBox("IP missing!")
Else
Dim ipAddress As Net.IPAddress = Net.Dns.GetHostEntry("127.0.0.1").AddressList(0)
dinleyici.Start()
Thread.Sleep(50)
dinlet.Start()
End If
End Sub
Private Sub dinlet_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dinlet.Tick
If dinleyici.Pending = 1 Then
msg = ""
client = dinleyici.AcceptTcpClient
Dim okuyucu As New StreamReader(client.GetStream)
While okuyucu.Peek > -1
msg = msg & Convert.ToChar(okuyucu.Read).ToString
End While
cevap.Text = msg
End If
End Sub
Private Sub gonder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gonder.Click
client = New TcpClient("127.0.0.1", Val(port.Text) + 1)
Dim yazici As New StreamWriter(client.GetStream)
yazici.Write(mesaj.Text)
Thread.Sleep(50)
yazici.Flush()
End Sub
End Class