|
-
April 8th, 1999, 03:18 AM
#1
CSocket and NT-Service
Hi,
I programmed a little MFC-tool which watches for incoming connections on a specific port.
After I ported it to an NT-MFC-Service this tool won't work any longer.
If I test my program with socktest I can login, but nothing more happens, it seems that my program don't execute the ACCEPT task ( I use onAccept ).
Who can help me out here, or can probably send me a short code example on how to use this with an NT-Service.
Thanx in advance
-
April 8th, 1999, 04:03 AM
#2
Re: CSocket and NT-Service
What account is your service running under? By default services run as LocalSystem, which does not have network access. Try changing it to run under an account which does have network access (use Control Panel, Services, Startup).
HTH
-
April 8th, 1999, 04:09 AM
#3
Re: CSocket and NT-Service
My program uses the ADMINISTRATOR account. So this don't seem to be the error.
Do u have another idea?
-
April 8th, 1999, 04:31 PM
#4
Re: CSocket and NT-Service
Your program must have a window and GetMessage(); DispatchMessage() cycle in main thread.
-
April 9th, 1999, 02:45 AM
#5
Re: CSocket and NT-Service
Hmm,
I guess this could be really the solution, but I want to have a service without a mainwindow. How can I get rid of it?
Do u have a solution on how to have this meesage cycle without a window?
-
April 23rd, 1999, 08:32 AM
#6
Re: CSocket and NT-Service
You cann't use CAsyncSocket class without main window. But you can use generic WinSock functions (connect, send etc).
-
April 23rd, 1999, 01:07 PM
#7
Re: CSocket and NT-Service
You can create hide window for service. For example:
VOID ServiceStart () {
WNDCLASS wc;
MSG msg;
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = NULL;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "AppName";
if (!RegisterClass(&wc)) {
return;
}
hWnd = CreateWindow( "AppName", NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
if (!hWnd) {
return;
}
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_CREATE:
/*
*/
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return 0;
}
-
April 25th, 1999, 06:14 AM
#8
Re: CSocket and NT-Service
Thank u very much, following lines worked:
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
:-)
-
May 6th, 1999, 04:44 AM
#9
Re: CSocket and NT-Service
Hi Karsten,
Can you brief me on How have you managed an existing application using sockets to be converted into an NT-Service, as I have made a socket appl. Now I want it to be converted into an NT-Service, How do i proceed ? Should I use ATL default service code for this and then incorporate my application or How should I proceed , enlighten me.
Thanks
SAnjeev
-
May 6th, 1999, 04:50 AM
#10
Re: CSocket and NT-Service
I used that MFCNTSERVICE Tool wich u can find here on codeguru. It was very simple, to implement my code into that ntservice code. all nt-service function have been there already.
-
May 6th, 1999, 05:26 AM
#11
Re: CSocket and NT-Service
Thanks guys,
This solved one of our problems too.
Frank.
-
May 6th, 1999, 11:38 AM
#12
Re: CSocket and NT-Service
Good idea, the MFC class CSocket use the windows message to implement the accept action,
so if your main thread does not any message loop, the OnAccept() would never be called,
the best method is create a listen thread which accept client, once any client connects, you
should create another thread for receive and send data with the client.
I have finish a NT service application two month ago, it listen a port and accept valid client and
communicate with it. but there are no CSocket object in the project, I use standart Socket API.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|