tcpListener.AcceptSocket strange behavior

  • Thread starter =?iso-8859-1?Q?Bj=F8rn_Eliasen?=
  • Start date
?

=?iso-8859-1?Q?Bj=F8rn_Eliasen?=

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 apps and installs to complete.

A scannig of ports indicates that the port used (2000) is free.

The application has two threeads. The listener thread described above and an other thread for managing user interaction using the systray. The listener thread has initially loaded a form, which is hidden while waiting for new sockets to connect.

Here is a some of the code:

Dim ip As IPAddress
ip = IPAddress.Any
tcplistener = New TcpListener(ip, myPort)
tcpListener.Start()
While True
Dim socket As Socket = tcpListener.AcceptSocket()

Any suggestions will be appriciatd.

Bjørn
 
C

Cor Ligthert [MVP]

Bjorn,

You can let your code run in a timerevent or you can let your thread sleep in the loop.
\\\\
threading.thread.sleep(milliseconds)
////

Now you are probably eating all your processor activitates in the loop.

I hope this helps,


Cor
"Bjørn Eliasen" <[email protected]> schreef in bericht 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 apps and installs to complete.

A scannig of ports indicates that the port used (2000) is free.

The application has two threeads. The listener thread described above and an other thread for managing user interaction using the systray. The listener thread has initially loaded a form, which is hidden while waiting for new sockets to connect.

Here is a some of the code:

Dim ip As IPAddress
ip = IPAddress.Any
tcplistener = New TcpListener(ip, myPort)
tcpListener.Start()
While True
Dim socket As Socket = tcpListener.AcceptSocket()

Any suggestions will be appriciatd.

Bjørn
 
?

=?iso-8859-1?Q?Bj=F8rn_Eliasen?=

Thanks for the suggestion,

It is only a few specific programs which fails and the cpu is not busy at all. As I understand I have to wait for a socket to connect constantly otherwise I migth fail to get a connection?

The line "Dim socket As Socket = tcpListener.AcceptSocket()" is just awaiting a new socket to connect and I can't really se how I can code any sleep functionality into this.

Bjørn




"Cor Ligthert [MVP]" <[email protected]> skrev i en meddelelse Bjorn,

You can let your code run in a timerevent or you can let your thread sleep in the loop.
\\\\
threading.thread.sleep(milliseconds)
////

Now you are probably eating all your processor activitates in the loop.

I hope this helps,


Cor
"Bjørn Eliasen" <[email protected]> schreef in bericht 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 apps and installs to complete.

A scannig of ports indicates that the port used (2000) is free.

The application has two threeads. The listener thread described above and an other thread for managing user interaction using the systray. The listener thread has initially loaded a form, which is hidden while waiting for new sockets to connect.

Here is a some of the code:

Dim ip As IPAddress
ip = IPAddress.Any
tcplistener = New TcpListener(ip, myPort)
tcpListener.Start()
While True
Dim socket As Socket = tcpListener.AcceptSocket()

Any suggestions will be appriciatd.

Bjørn
 
G

Guest

Side talk:
Just wondering how can your client socket detect connection dropped by your
server socket?
(ie., when your tcpListener socket dropped, how can the other side of your
tcpClient socket know about it?)
 

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