Help needed: TCP Server questions/problems

M

Matthew Speed

(About me: I know very little about writing server applications. I
have done plenty of VB6 desktop app work but this is my first server
program. I got it to work by modifying examples. I understand what
it is doing but not much about what is involved in extending it. )

I am not necessarily looking for code examples here, just some
pointers as to what direction I need to proceed to resolve these
things.

I have written a multithreaded TCP/IP server. This program's job is
to listen to requests from a Java program running on some wireless
phones. On the server side it interacts with SQL Server 2000. It
accepts connections, is passed login credentials, recieves some data
update from the client and sends back some results. The program
itself works fine. I am now trying to improve upon it and have run
into the following issues/problems:

1. I want this to run as a Windows service a la SMTP. When it runs as
an interactive program it consumes 5-8% of the CPU time. When it runs
as a service it consumes all it can get. When it runs it is ALWAYS
the top CPU user on the machine. I like to think that when clients
aren't connected it shouldn't be using 90% of the CPU time.

2. I would like to be able to monitor what it is doing. When I ran
it as a console app I could write out messages to the console telling
me how many clients were connected and what they were sending or being
sent. I would like to wite a monitor program that can tap into the
service that can receive the equivalent messages to be displayed in a
text window since services don't get to talk to the console. My first
thoughts would be to try to treat it like a COM object and raise
events but I don't know if that model works in VB.Net or with services
in general.

3. I would like to be able to log each clients' conversation to a
text file for review. I created a logfile class with open,write and
close methods that creates/opens a log file. This works fine in the
console app but the service app seems unable to do this. Do services
have the ability to write to the filesystem?

TIA
 
G

Glenn Wilson

Have a look at remoting for the monitoring of you app. For the file system
question, make the service run under a user name, and allow that user to
have permissions on the file system.

GW
 
G

Gary Chang

Hi Matthew,

Thanks for posting in the community.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
P

Peter Huang

Hi Matthew,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to create a TCP/IP
server as an windows service.
Also you wants to monitor the service with an UI application(winform app)
and write to file. And you find the application will exaust all the CPU
when there is no active connection.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I agree with Glenn's suggestion that utilized the remoting the do the IPC
between the windows service and the monitor APP. You can also handle the
remoting object's event to achieve your aim.

How To: Host a Remote Object in a Windows Service
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/ht
ml/SecNetHT15.asp

Windows Service can access the file system, but you need to check if the
account you use the run the service has the permission to access to the log
file you want to write to.

As for the first question, I suggest you may check if there is any
difference between the code between console application and the windows
services. Usually a standard Server Socket application will suspend at a
line similar with below to wait for conncetion from client.
' Program is suspended while waiting for an incoming
connection.
Dim handler As Socket = listener.Accept()
Since your application is high CPU consumer when there is no client
connection, so you may try to debug into the windows service to see which
code line cause the high CPU time consumption.

To debug an windows service, you may need to attach vs.net debugger to a
running windows service

Debugging Windows Service Applications
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskdebuggingserviceapplications.asp

If you will accept multiple connections at one time in the services, I
think the Asynchronous invoking will be good pratices.

Asynchronous Server Socket Example
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconnon-blockingserversocketexample.asp

Asynchronous Client Socket Example
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconnon-blockingclientsocketexample.asp

If you have any concern on this issue, please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi Matthew,

Thanks for posting in the community.

If you have any concern on this issue, please feel free to post here and I
will work on it with you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Matthew Speed

Thank you for your response. I will look into each of these over the
next few days and add to my application to determine whether or not
those do what I am looking for.
 

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