|
I tried some sample programs in C++, VC++ and Java to check if two server can bind to the same port, but they failed, they got the conflict error.
But i found out on some web-sites that some time, on window 2000/XP platform, two instances of server can still bind to the same port, (it looks like an error of OS rather than programing error, i think so). In this case, only one instance of server can get traffic from clients. But the other instance, instead of failing in binding, it still runs and gets the listening state. T_T
Do you know more about this problem?
(And thank you very much, Mark)
|
|
|
|
|
lchild385 wrote: But i found out on some web-sites that some time, on window 2000/XP platform, two instances of server can still bind to the same port, (it looks like an error of OS rather than programing error, i think so). In this case, only one instance of server can get traffic from clients. But the other instance, instead of failing in binding, it still runs and gets the listening state.
I'm not sure how that would/could/should work either
It IS possible to bind to the same port using two different protocols...for example, you
can use UDP on the same port number a TCP socket is "listening" on.
lchild385 wrote: (And thank you very much, Mark)
You're welcome! (I don't think I've helped any haha)
Mark
|
|
|
|
|
Hi, now is exactly my problem. I have server program JServer and client program JClient in Java language, and I have server program CServer and client program CClient in VC++ language too. The problem is two server programs JServer and CServer can bind normally to the same port (use the same protocol TCP) and client program JClient and CClient can communicate normally with the correlative server program like two independent system (JClient with JServer, CClient with CServer).
I have to research the reason and the way to avoid this problem when programming. But to now, I have not ever coding such program to check if this problem can happen (all my programs get conflict error). But this problem has really happended (my lecturer checked it).
Maybe this problem is so reraly to happend and there are not much people met it. T_T
( What should i do now, my God!!!!!!!!!!!!!!!!! )
(i don't know why my account (lchild385) becomes hapc @_@. who is hapc???)
|
|
|
|
|
hapc wrote: The problem is two server programs JServer and CServer can bind normally to the same port (use the same protocol TCP) and client program JClient and CClient can communicate normally with the correlative server program like two independent system (JClient with JServer, CClient with CServer).
I still don't believe it unless someone is setting it up to be able to
From MSDN:
By default, a socket cannot be bound (see bind) to a local address that is already in use. On
occasion, however, it can be necessary to reuse an address in this way. Since every connection is
uniquely identified by the combination of local and remote addresses, there is no problem with
having two sockets bound to the same local address as long as the remote addresses are different.
On Windows Sockets 2 you can use setsockopt() to set SO_EXCLUSIVEADDRUSE to TRUE.
Check this info: Using SO_EXCLUSIVEADDRUSE[^]
Mark
|
|
|
|
|
p.s.
who is hapc???
|
|
|
|
|
Hi,
I am trying to copy to the clipboard a part of an image. I know all the pixels that should be copied and I can create a HRGN / CRgn object that represent the region that should be copied.
I know that I should use the SetClipboardData(UINT uFormat, HANDLE hMem).
I need help with which format and hMem should I use. How do I create the HANDLE that will represent only the region that I wish to copt and not the hole image?
Thanks,
Yaron.
|
|
|
|
|
An easy way is to create a new bitmap the size of the region rect.
Step through each source pixel in the region rect and use PtInRegion() to determine if it's in
the region. If it is, copy the pixel to the new bitmap. If not write a background-color pixel
to the new bitmap. Then place the bitmap on the clipboard.
Another way is create a new bitmap (DIB section) the size of the region rect.
Select it into a memory DC
Use StretchBlt() or whatever to draw the source region rect to the dc.
If the region is not rectangular go through the pixels using PtInRegion() like above to
remove the pixels outside the region.
Mark
|
|
|
|
|
Thanks for your help.
This is probabely a silly question, but placing a background-color will cause the image to be copied with a background in the specified color and not as cliped one, right?
Anyway this is what I did and I tried to set those pixels to be transparent but it didn't work for me for some reason (I set the rgbReserved member of RGBQUAD to 0 and also tried 255), I still get the color I have set as a bg. What should I do so that when I paste the image, the bg will be transparent?
thanks,
Yaron.
|
|
|
|
|
That would depend on which function you use to blit it to the screen.
Regular GDI you have to use an AND mask to get transparency.
GDI+ you can use the alpha channel byte.
Mark
|
|
|
|
|
Probably a stupid question, but I can't seem to get his to work. I have an array of 20 DWORD values, each DWORD represents a 20 pixel line in a bitmap. How can I convert this array into a bitmap handle (HBITMAP)?
I have tried calling CreateDIBSection() then copy the array data over to the retrieved void pointer, but I am unable to display the image. All I see is a black square which tells me the bitmap has not been created correctly.
|
|
|
|
|
Are you setting up the BITMAPINFO structure correctly for the format of your pixels?
Mark
|
|
|
|
|
Yeah. It was my own stupid fault, I had the byte order the wrong way around. 3 hours of debugging just to find that!
|
|
|
|
|
waldermort wrote: 3 hours of debugging just to find that!
Fun Fun! Glad you found it!
Mark
|
|
|
|
|
Q1
As we know that in a windows application whenever a key is pressed, a message is sent to the active window. We are developing a DOS based application and want to detect whenever a key is pressed from keyboard. How can we do so?
Q2
We are writing a DOS based application in which we have to display the system date and time. Write down the code for doing so.
|
|
|
|
|
Q1 kbhit
Q2 #include <time.h>
Good luck with your homework
|
|
|
|
|
|
I think you asked these questions and you get answers.
|
|
|
|
|
I want to hook the WM_MOUSEWHEEL msg in globel and identify whether it is scroll in or scroll out by 'zDelta', but the 'zDelta'(below) always seem to be zero. Can any one help me.
Thanks!
extern "C" _declspec(dllexport) LRESULT WINAPI MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if(nCode < 0)
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
if(nCode == HC_ACTION)
{
switch(wParam)
{
case WM_MOUSEWHEEL:
short zDelta = (short)HIWORD(wParam);
break;
...........
default:
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
}
}
}
|
|
|
|
|
Michael ZY wrote: extern "C" _declspec(dllexport) LRESULT WINAPI MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
I'm not sure why zdelta would be zero all the time.
Is "extern "C" the same linkage as __stdcall?
The hook func needs to be __stdcall.
try
extern _declspec(dllexport) LRESULT CALLBACK WINAPI MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
Mark
|
|
|
|
|
Thanks for reply, but still not Work.
i hooked other mouse msg like WM_LBUTTONDOWN are all fine.
Is that use the WH_MOUSE can not identify wheel scroll direction (need WH_MOUSE_LL?)
what i use now is:
g_hHook=SetWindowsHookEx(WH_MOUSE,MouseProc,g_hInstance,0);
|
|
|
|
|
I see it.
short zDelta = (short)HIWORD(wParam);
won't work. wParam is WM_MOUSEWHEEL, not the wheel delta
extern "C" _declspec(dllexport) LRESULT WINAPI MouseProc(int nCode,WPARAM wParam,LPARAM lParam){
if(nCode < 0)
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
if(nCode == HC_ACTION)
{
switch(wParam)
{
case WM_MOUSEWHEEL:
short zDelta = (short)HIWORD(wParam);
break;
default:
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
}
}
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
}
I can't find how to get the wheel delta in a hook proc LOL I'll let you know when/if I do!
Mark
|
|
|
|
|
|
Got it!
Thanks a lot Mark!
Use the code like this:
case WM_MOUSEWHEEL:
{
typedef struct
{
MOUSEHOOKSTRUCT MOUSEHOOKSTRUCT;
DWORD mouseData;
}MOUSEHOOKSTRUCTEX,*PMOUSEHOOKSTRUCTEX;
MOUSEHOOKSTRUCTEX *MHSEX;
MHSEX=(MOUSEHOOKSTRUCTEX*)lParam;
if(MHSEX->mouseData==(WHEEL_DELTA<<16))
AfxMessageBox("up");
if(MHSEX->mouseData==(-WHEEL_DELTA<<16))
AfxMessageBox("down");
}
break;
|
|
|
|
|
I need to catch every keyboard event before operation system ( windows xp ) does.
What i mean is in case user click on key 'enter' ( or every other key ) my application need to check if the key is 'X' key - and in any case this key event need to continue as key event to the operation system.
I'm sure there is some win32 API function to do it - but i don't remember it.
Someone can help me ?
Thanks.
|
|
|
|
|
Yanshof wrote: I need to catch every keyboard event before operation system ( windows xp ) does.
Yanshof wrote: I'm sure there is some win32 API function to do it - but i don't remember it.
Do you see a contradiction between those 2 sentences??
|
|
|
|