I put together a little app that runs a TCPListener and TCPClient class. I wanted to enable them to send little messages back and forth. I've disabled the firewall completely for testing purposes.
Server Code
The Client Side Code
The problem is I get the 10061 Error of: No connection could be made because the target machine actively refused it. Not sure what to do about it at this point.
All lessons learned from the School of Hard Knocks........at least tuition is cheap.
Server Code
Code:
Public Class ServerSide
Private _TCPListener As New TcpListener(IPAddress.Any, 23000)
Private WithEvents _Timer As System.Timers.Timer = New System.Timers.Timer
Private _TCP As TcpClient
Private _NetStream As NetworkStream
Private _SReader As StreamReader
Private _Message As String
Public Event ConnectionFound()
Public ReadOnly Property Message()
Get
Return _Message
End Get
End Property
Public Sub Start()
_TCPListener.Start()
End Sub
Private Sub Timer_Elapsed() Handles _Timer.Elapsed
If _TCPListener.Pending Then
_TCP = _TCPListener.AcceptTcpClient
_NetStream = _TCP.GetStream
_SReader = New StreamReader(_NetStream)
_Message = _SReader.ReadToEnd
RaiseEvent ConnectionFound()
End If
End Sub
End Class
The Client Side Code
Code:
Public Class ClientSide
Private _TCP As TcpClient = Nothing
Private _SWriter As StreamWriter = Nothing
Private _NetStream As NetworkStream = Nothing
Public Sub New()
_TCP = New TcpClient
Try
_TCP.Connect("localhost", 23000)
Catch ex As Exception
_TCP.Connect("localhost", 23000)
End Try
_NetStream = _TCP.GetStream
End Sub
Public Sub SendMessage(ByVal Message As String)
_SWriter = New StreamWriter(_NetStream)
_SWriter.WriteLine(Message)
If _SWriter IsNot Nothing Then
_SWriter.Close()
End If
End Sub
Public Sub Close()
If _TCP IsNot Nothing Then
_TCP.Close()
End If
End Sub
End Class
The problem is I get the 10061 Error of: No connection could be made because the target machine actively refused it. Not sure what to do about it at this point.
All lessons learned from the School of Hard Knocks........at least tuition is cheap.