954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problems with TcpListener and TcpClient

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

delizihin
Newbie Poster
2 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: