Luc
Well-known member
- Joined
- Nov 29, 2005
- Messages
- 59
- Programming Experience
- 1-3
I've never really tried programming network and internet stuff with VB.net so I tried writing a simple TCP/IP chatbox, although I'm encountering some problems, since my VS is in dutch I'll try to transalate the error as good as I can. Here's the source:
Main form:
And the Listen class:
The error translated is:
Anny help and comment is apreciated thx
Main form:
VB.NET:
Dim localIp As IPAddress
Public Shared strIP As String
Public Event Incomming_msg(ByVal msg As String)
Private WithEvents mlisten As New listen
Private thrdListener As New Threading.Thread(AddressOf mlisten.listen)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
thrdListener.Start()
strIP = InputBox("geef de chatter zijn IP in aub")
localIp = System.Net.IPAddress.Parse(strIP)
End Sub
Private Sub btnsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsend.Click
Dim objClient As New Net.Sockets.TcpClient
objClient.Connect(IPAddress.Parse(strIP), 6580)
Dim sw As New StreamWriter(objClient.GetStream)
sw.Write(TXTsend.Text)
sw.Flush()
sw.Close()
objClient.Close()
End Sub
Private Sub incomming_messages(ByVal str As String) Handles mlisten.incomming_msg
TXTmsg.AppendText(str & vbCrLf)
End Sub
VB.NET:
Imports System.io
Public Class listen
Event incomming_msg(ByVal msg As String)
Private objListener As New Net.Sockets.TcpListener(6580)
Public Sub listen()
Dim objclient_ As Net.Sockets.TcpClient
Dim sr As StreamReader
Dim LocalIP As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")
objListener = New Net.Sockets.TcpListener(LocalIP, 6580)
Dim line$
Do While 1
objListener.Start()
objclient_ = objListener.AcceptTcpClient()
sr = New StreamReader(objclient_.GetStream)
While sr.Peek > -1
line += sr.ReadLine
End While
RaiseEvent incomming_msg(line)
line = String.Empty
Loop
End Sub
End Class
the error in dutch is:An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll
Additional information: A connectionattempt has failed caused the connected party did not respond after a small time, or the created connection failed cause the connected didn't answer.
I tested this with a friend of mine and I'm pretty sure he send me the right IP. Both partys have disabled their firewall and I opened the needed ports on my router, but might the error be that he has to open his ports to? If this is so then what port could I use without needing to do forward porting?An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll
Additional information: Een verbindingspoging is mislukt omdat de verbonden party niet correct heeft geantwoord na een bepaalde tijd, of de gemaakte verbinding is mislukt omdat de verbonden host niet heeft geantwoord
Anny help and comment is apreciated thx