TCP send & Recieve

T

Tlink

I have have lifted some code that I am trying to make work in 2 seperate
projects it appears to send okay but the it only recieves once then it stop
recieving I am unsure as to why ?

******** sending ****
Private Sub SendAction(ByVal DoAction, ByVal RemoteAddress)
Dim Actionport As Integer = 40000
Dim TCPClient As New TcpClient(RemoteAddress, Actionport)
Dim TCPNetworkStream As NetworkStream = TCPClient.GetStream
Dim TCPStreamWriter As New StreamWriter(TCPNetworkStream)
Try
TCPStreamWriter.Write(DoAction)
Catch ex As Exception
ErrorCondition = ex.Message
End Try
TCPStreamWriter.Close()
TCPNetworkStream.Close()
TCPClient.Close()
End Sub



****** recieving *****

Dim localhostaddress As IPAddress = MSearchObj.ActiveIP

Dim Lport As Integer = 40000
Dim TcpListener As New TcpListener(localhostaddress, Lport)
TcpListener.Start()

Dim TCPClient As TcpClient = TcpListener.AcceptTcpClient()
Dim TCPNetworkStream As NetworkStream = TCPClient.GetStream
Dim TCPStreamReader As New StreamReader(TCPNetworkStream)

errorcondition = ""
Do While errorcondition.Length = 0

RecievedData = ""
SendData = ""

If TcpListener.Pending = False Then
Thread.Sleep(100)
Else
Do While TCPStreamReader.EndOfStream = False
RecievedData = TCPStreamReader.ReadLine
If RecievedData <> "" Then
ProcessInput(RecievedData, SendData, MSearchObj,
DBobj)
End If
Loop
Thread.Sleep(1000)
End If
Loop
 
V

vbnetdev

Try not using the close statements at the end. You are disconnecting
yourself with these statements.
 
V

vbnetdev

Hi,

Send zipped project to

(e-mail address removed)

remove no spam and let me see what I can do.

Kelly
 
T

Tlink

Kelly,

worked it out, the solution is to the place all the processing items
within the do while loop this ensures that the active listener is active and
ready.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top