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