By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,989 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,989 IT Pros & Developers. It's quick & easy.

TCPListener.socket closes on send

P: n/a
Hi,

I'm using VB in VS2005 on a WXP SP2 machine to build a windows service
that listens to a port to accept messages. This solution works fine
when a connecting client sends a message, waits for an ACK and
disconnects. We now want the socket to remain OPEN after sending the
ACK, which it used to do on beta2 and older machines.

Does anyone know which property to set or another solution to keep the
socket open after the send.

Any ideas?

Bert

Here's the code:

Public Sub StartGateway()
CommServerListener = New
TcpListener(IPAddress.Parse(HostIpAddress), CommServerUnsollicitedPort)
CommServerListener.Start()
Timer2 = New System.Timers.Timer(1000)
Timer2.Enabled = True
End Sub

Public Sub Timer2_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer2.Elapsed
If h.CommServerListener.Pending() Then
Timer2.Enabled = False
ProcessCloverleafRequest()
Timer2.Enabled = True
End If
End Sub

Public Sub ProcessCloverleafRequest()
Dim Buffer As Byte() = New Byte(TcpBufferSize) {}
Dim NumberOfBytes As Integer
Dim Temp As String
Dim msg As String
Dim iStart, iEnd As Integer
If ListenerSocket Is Nothing Then
ListenerSocket = CommServerListener.AcceptSocket
End If
Temp = String.Empty
If ListenerSocket.Available > 0 Then
ReDim Buffer(ListenerSocket.Available) 'JL300805: take all
messages available
NumberOfBytes = CInt(ListenerSocket.Available)
ListenerSocket.Receive(Buffer, Buffer.Length,
SocketFlags.None)
If NumberOfBytes > 0 Then
'....do stuff
'when finished echo message
ListenerSocket.Send(Buffer, 0, Buffer.Length,
SocketFlags.none)
'Here one would expect that this instruction doesn't close
the connection
'anyway the connection should stay open
End Sub

Mar 30 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.