473,624 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TCPListener.soc ket closes on send

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()
CommServerListe ner = New
TcpListener(IPA ddress.Parse(Ho stIpAddress), CommServerUnsol licitedPort)
CommServerListe ner.Start()
Timer2 = New System.Timers.T imer(1000)
Timer2.Enabled = True
End Sub

Public Sub Timer2_Elapsed( ByVal sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles Timer2.Elapsed
If h.CommServerLis tener.Pending() Then
Timer2.Enabled = False
ProcessCloverle afRequest()
Timer2.Enabled = True
End If
End Sub

Public Sub ProcessCloverle afRequest()
Dim Buffer As Byte() = New Byte(TcpBufferS ize) {}
Dim NumberOfBytes As Integer
Dim Temp As String
Dim msg As String
Dim iStart, iEnd As Integer
If ListenerSocket Is Nothing Then
ListenerSocket = CommServerListe ner.AcceptSocke t
End If
Temp = String.Empty
If ListenerSocket. Available > 0 Then
ReDim Buffer(Listener Socket.Availabl e) 'JL300805: take all
messages available
NumberOfBytes = CInt(ListenerSo cket.Available)
ListenerSocket. Receive(Buffer, Buffer.Length,
SocketFlags.Non e)
If NumberOfBytes > 0 Then
'....do stuff
'when finished echo message
ListenerSocket. Send(Buffer, 0, Buffer.Length,
SocketFlags.non e)
'Here one would expect that this instruction doesn't close
the connection
'anyway the connection should stay open
End Sub

Mar 30 '06 #1
0 1076

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4394
by: Rob White | last post by:
OK, so I have a TcpListener that is waiting for sockets, this piece of code: IPAddress localAddress = Dns.GetHostByName(Dns.GetHostName()).AddressList; IPEndPoint localEP = new IPEndPoint(localAddress, 9000); TcpListener tcpListen = new TcpListener(localEP); tcpListen.Start(); Socket skt = tcpListen.AcceptSocket(); .... do some socket stuff skt.Close();
1
2456
by: Claire | last post by:
Hi Im writing an application using the above controls in blocking mode. Ive not used them before and I'm more used to asynchronous socket programming utilizing socket events. As there are no events associated to the controls, I'm wondering how i monitor connection state. On my server side, i loop through a thread that tests the DataAvailable flag. On client side, i opened the connection then closed it again after some time
2
702
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no more data to expect). Sometimes, Socket.Available returns 0 but the other end of the connection did not close it ! 2) This class will be used by many other classes so I have to use the
4
11380
by: Haim | last post by:
it is very strange for me that a simple event of closing socket that was in the the winsock object of vb6 , i didn't found yet in the vb.net the only way i found is to try to send something to the socket and if i got error then the socket is closed. there must be a way to get this event without trying to send something , since it is in the lower level
23
4377
by: iwdu15 | last post by:
hi i have a working code for a tcpclient, but i cant seemt of figure out how to use a tcplistener to connect with it. i just want to clck a button and listen for a TCP conection and conect to a specific port, but any attempt i try fails....any help would b awsome -- -iwdu15
2
4054
by: Terry Olsen | last post by:
Hoping someone can help me here. I've got this code written, and it works fine for the first connection. But if I connect another client (while the first is still connected), I get connected but nothing else, no data exchange. If I disconnect the 2nd session, I get a System.IO.IOException. If I disconnect the first session with the 2nd session still connected, then all the data I typed in the 2nd session gets returned to me as if it was...
2
2800
by: Nuno Magalhaes | last post by:
How to check for a closed http socket without losing any data? (MSDN says to send something to server). Somewhere in my code (after sending the http header in plain text) I'm doing a loop with: Loop:---------------- Socket.Receive //receive http data chunks Socket.Send //'/r/n' data to check if connection is active ------------------------ The problem is that when connection is closed by the http server, the send socket function...
3
4350
by: Bjørn Eliasen | last post by:
Hi, I have an application running on all pc's in our company. Basically it is a TCPListener awaiting for sockets to connect and on connection performs the required tasks. The app works fine, but while the listener is awaiting for socket to connect several other applications can't start, and even installation of new applications migth hang. In order to finalise the other apps or installations the tcp listener is killed resulting in the other...
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.