Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer Effect without a Timer 4

Status
Not open for further replies.

Genimuse

Programmer
Joined
May 15, 2003
Messages
1,797
Location
US
I'm working on a "server" application that will have no user interface -- it'll be a console application. (It's on the PocketPC, but I doubt that changes the possible answers too much).

As a server, it sits and listens for requests on a TCP socket. The "standard" way of doing this seems to be to have a timer control that fires every .x seconds that runs a process that checks the buffer for data.

This works fine except when I have no forms and no controls. How can I check the buffer every so often without a timer?
 
I don't think you need to. Just start a TCP listener and it will pop when a 'client' attachs.

This is a code snippet that I use.

' Now start the listener

Dim LocalEndPoint As New IPEndPoint(H.AddressList(0), ourPort)
Dim Listener As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

Try
Listener.Bind(LocalEndPoint)
Listener.Listen(10) ' allow 10 backlogs
Message = " : Waiting for connection to " & shostname & "(" & IPAddress & ") port " & ourPort.ToString
Do
Dim handle As Socket = Listener.Accept()
.
.
.
.
.
.
Loop Until
 
You can create a timer object in code:

Dim WithEvents timer1 As System.Timers.Timer

timer1 = New System.Timers.Timer
timer1.Interval = 1000
timer1.Start()

Here's the event handler for the timer's Elapsed event:

Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer1.Elapsed

MsgBox("Time!")

End Sub

This is in the "regular" .NET framework...I'm not sure about the Compact framework.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
kevinf2349, thank you. What do I need to import to get an IPEndPoint object. I assumed that importing System.Net.IPEndPoint would do it, but no luck.

jebenson, thank you, too. Same question, though, on System.Timers... what do I need to import/reference to have them available?

Sorry for the newbie questions, and thank you both.
 
BTW, those two questions might indicate that they're not available in the compact framework. MSDN is sure useless when it comes to figuring out whether or not something's available in the CF2.
 
Actually there are several timer classes, all with their own uses

one in system.windows.forms
one in system.timers
one in system.threading

probably one is available in the CF

I would prefer the threading one but it's a bit harder to implement.

Sorry for the bad spelling.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Thanks guys. I can't find a timer class anywhere in the compact framework (except for the component), but will keep trying to find one.

Alternately can I sleep something, or is that bad juju?
 
yes thread.sleep() should work but it is a bad thing.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top