PC Review


Reply
Thread Tools Rate Thread

How to terminate a window which is running a listener?

 
 
hyzong
Guest
Posts: n/a
 
      23rd Feb 2005

I have a Window program (vb) which has a UDP listener. I'm having
problem terminating this program as the program is listening to a port
and not to my btnExit_Click event.

Here is the code:

Dim sErr As String = ""
Dim sLog As String = ""
Dim ipAddress As IPAddress

'Create a UDP socket.
Dim listener As Socket = New Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp)

Dim ipHostInfo As IPHostEntry

ipHostInfo = Dns.Resolve(Dns.GetHostName())
ipAddress = ipHostInfo.AddressList(0)
Dim localEndPoint As New IPEndPoint(ipAddress, CType(sPortNumb,
Integer))

listener.Bind(localEndPoint)

Dim msgLen As Int32 = 900
Dim i As Int32
Dim received(900) As Byte

While Not (bTerminated)
For i = 0 To msgLen - 1
received(i) = Byte.Parse("0")
Next

Dim tmpIpEndPoint As IPEndPoint = New IPEndPoint(ipAddress,
CType(sPortNumb, Integer))

Application.DoEvents()
Dim remoteEP As EndPoint = (tmpIpEndPoint)
Dim bytesReceived As Integer = listener.ReceiveFrom(received,
remoteEP)

Dim sRecvd As String =
Encoding.ASCII.GetString(received).Trim(Chr(0))

txtMsg.text = "Message Received: " & sRecvd
Application.DoEvents()

tmpIpEndPoint = Nothing

End While

listener.Shutdown(SocketShutdown.Receive)
listener.Close()
listener = Nothing


Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
bTerminated = True
me.Close()
End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
command to terminate a running program? A.E lover Windows XP Help 5 19th May 2008 05:31 PM
Check if process running then terminate if is? Smokey Grindel Microsoft VB .NET 3 10th Apr 2008 11:50 PM
Terminate running program from .bat file? Sid Elbow Microsoft Windows 2000 3 7th Feb 2008 04:35 PM
Terminate Running Program Alan Microsoft VB .NET 2 9th Mar 2004 08:09 PM
How do I keep the TCP/IP listener running? Chris Microsoft VB .NET 2 27th Feb 2004 06:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:08 AM.