PC Review


Reply
Thread Tools Rate Thread

How do I keep the TCP/IP listener running?

 
 
Chris
Guest
Posts: n/a
 
      26th Feb 2004
I took some samples from the net to help me create a TCP/IP socket
listener. I stripped out most of the code and put it below. Bottom
line is when I receive the ***END*** line from the client, the client
is done sending me data. Of course when this happens, my server
stops. I would like to know how to keep the server listening after
the client is done communicating. I'm sure most of the reason it stops
is that everything is in Sub Main. I did see some samples on
threading connections but I don't need that. Just one connection at a
time. This works perfectly otherwise.

Thanks for help,

Chris

Imports System.Net.Sockets
Imports System.Net
Imports System.Net.WebProxy
Imports System.IO
Imports System
Imports System.Text.RegularExpressions
Class TCPSrv
Shared Sub Main()
Dim servermessage As String
Dim clientmessage As String
Const portNumber As Integer = 8100
Dim tcpListener As New TcpListener(portNumber)
tcpListener.Start()
Console.WriteLine("Waiting for connection...")
Dim socketforClient As Socket
socketforClient = tcpListener.AcceptSocket()
Dim NetworkStream As NetworkStream
networkStream = New NetworkStream(socketforClient)
Dim streamWriter As StreamWriter
streamWriter = New StreamWriter(NetworkStream)
Dim streamReader As StreamReader
streamReader = New StreamReader(NetworkStream)
Dim strPage As String

Do While (Status)
If socketforClient.Connected Then
servermessage = streamReader.ReadLine()
If servermessage = "***END***" Then
Status = False
Exit Do
End If
clientmessage = "Response to the client"
streamWriter.WriteLine(clientmessage)
streamWriter.Flush()
End If
Console.WriteLine(servermessage)
streamWriter.Flush()

Loop
End Sub
End Class
 
Reply With Quote
 
 
 
 
Bryan Martin
Guest
Posts: n/a
 
      26th Feb 2004
http://msdn.microsoft.com/library/de...ketexample.asp

Take special note to the manual reset event.

Bryan Martin

"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I took some samples from the net to help me create a TCP/IP socket
> listener. I stripped out most of the code and put it below. Bottom
> line is when I receive the ***END*** line from the client, the client
> is done sending me data. Of course when this happens, my server
> stops. I would like to know how to keep the server listening after
> the client is done communicating. I'm sure most of the reason it stops
> is that everything is in Sub Main. I did see some samples on
> threading connections but I don't need that. Just one connection at a
> time. This works perfectly otherwise.
>
> Thanks for help,
>
> Chris
>
> Imports System.Net.Sockets
> Imports System.Net
> Imports System.Net.WebProxy
> Imports System.IO
> Imports System
> Imports System.Text.RegularExpressions
> Class TCPSrv
> Shared Sub Main()
> Dim servermessage As String
> Dim clientmessage As String
> Const portNumber As Integer = 8100
> Dim tcpListener As New TcpListener(portNumber)
> tcpListener.Start()
> Console.WriteLine("Waiting for connection...")
> Dim socketforClient As Socket
> socketforClient = tcpListener.AcceptSocket()
> Dim NetworkStream As NetworkStream
> networkStream = New NetworkStream(socketforClient)
> Dim streamWriter As StreamWriter
> streamWriter = New StreamWriter(NetworkStream)
> Dim streamReader As StreamReader
> streamReader = New StreamReader(NetworkStream)
> Dim strPage As String
>
> Do While (Status)
> If socketforClient.Connected Then
> servermessage = streamReader.ReadLine()
> If servermessage = "***END***" Then
> Status = False
> Exit Do
> End If
> clientmessage = "Response to the client"
> streamWriter.WriteLine(clientmessage)
> streamWriter.Flush()
> End If
> Console.WriteLine(servermessage)
> streamWriter.Flush()
>
> Loop
> End Sub
> End Class



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      27th Feb 2004
Thanks alot for your help. I picked the Synchronous sample which
worked for me very well.

"Bryan Martin" <(E-Mail Removed)> wrote in message news:<uRe0LSL$(E-Mail Removed)>...
> http://msdn.microsoft.com/library/de...ketexample.asp
>
> Take special note to the manual reset event.
>
> Bryan Martin
>
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I took some samples from the net to help me create a TCP/IP socket
> > listener. I stripped out most of the code and put it below. Bottom
> > line is when I receive the ***END*** line from the client, the client
> > is done sending me data. Of course when this happens, my server
> > stops. I would like to know how to keep the server listening after
> > the client is done communicating. I'm sure most of the reason it stops
> > is that everything is in Sub Main. I did see some samples on
> > threading connections but I don't need that. Just one connection at a
> > time. This works perfectly otherwise.
> >
> > Thanks for help,
> >
> > Chris
> >
> > Imports System.Net.Sockets
> > Imports System.Net
> > Imports System.Net.WebProxy
> > Imports System.IO
> > Imports System
> > Imports System.Text.RegularExpressions
> > Class TCPSrv
> > Shared Sub Main()
> > Dim servermessage As String
> > Dim clientmessage As String
> > Const portNumber As Integer = 8100
> > Dim tcpListener As New TcpListener(portNumber)
> > tcpListener.Start()
> > Console.WriteLine("Waiting for connection...")
> > Dim socketforClient As Socket
> > socketforClient = tcpListener.AcceptSocket()
> > Dim NetworkStream As NetworkStream
> > networkStream = New NetworkStream(socketforClient)
> > Dim streamWriter As StreamWriter
> > streamWriter = New StreamWriter(NetworkStream)
> > Dim streamReader As StreamReader
> > streamReader = New StreamReader(NetworkStream)
> > Dim strPage As String
> >
> > Do While (Status)
> > If socketforClient.Connected Then
> > servermessage = streamReader.ReadLine()
> > If servermessage = "***END***" Then
> > Status = False
> > Exit Do
> > End If
> > clientmessage = "Response to the client"
> > streamWriter.WriteLine(clientmessage)
> > streamWriter.Flush()
> > End If
> > Console.WriteLine(servermessage)
> > streamWriter.Flush()
> >
> > Loop
> > End Sub
> > End Class

 
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
TCP listener Markgoldin Microsoft C# .NET 7 19th Jul 2008 06:07 PM
RE: Key listener =?Utf-8?B?UmFZ?= Microsoft Excel Programming 1 10th Dec 2006 09:03 PM
RDP Listener =?Utf-8?B?UERQLThF?= Microsoft Windows 2000 Terminal Server Clients 0 2nd Dec 2005 05:51 PM
How to terminate a window which is running a listener? hyzong Microsoft Dot NET Framework 0 23rd Feb 2005 06:06 PM
RDP-listener M$ Microsoft Windows 2000 Terminal Server Clients 6 6th Nov 2004 09:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:23 AM.