|
Thanks for the reply. I was recently suggested to add shutdown(socket, SD_BOTH); this made it more reliable, but still not 100%. At the moment it seems that connect function just freezes for a few seconds and then returns that it failed (to connect to the server) The connection is however fine, as both before and after it kept going. This seems to happend at random intervals. (between ~100 connections to ~2500)
Right now though, im probably re connecting every 50-100ms (cant remember)...
Note that what i pasted from netstat is just a little of it, there were so many i cant even copy them all as they go beyong max content of a normal cmd window...
I would (if possible) like to stay with a non-constant connection, as this is easier for me (if i get it to work) + faster on a unreliable connection.
Thanks
//Johannes
|
|
|
|
|
Hi again! Without the error code it is hard to figure out what is going wrong and I can only guess. Maybe your are using hostnames (rather than IPs) and the DNS resolution blocks when connecting or you didn't close sockets properly (in client or server code) and reached an upper limit per process. In any case, your application will only work inside the LAN very well, on the internet you will probably encounter longer round trips than 50-100ms and the TCP handshake alone probably takes more time than sending your payload data. Again I am only guessing... it would be helpful to see code, error codes or your application requirements.
Hope it helps.
|
|
|
|
|
Hey,
connect(theSocket,(LPSOCKADDR)&serverInfo, sizeof(serverInfo)); is returning -1 ( SOCKET_ERROR ). It seems to happend just randomy. This time it occured after ~7000 connections. My program does resolve a DNS name, which is placed inside the hosts file (like localhost), that should work instantly...
It just errord again, once more now. There is a very long time between between connect attemp, and when it returns -1 , maybe like ~15 seconds...
Yea, my program is only gonna run on a direct LAN, or maybe between a few switches/router.
I want a simple and reliable way to send a 64char string, if i use TCP/UDP/ICMP/Multicast doesnt really matter, and my server side doesnt need to know if the data came to the client or not...
Thanks!
//Johannes
|
|
|
|
|
Maybe your are running out of socket objects. Again I am only guessing... it would be helpful to see source code and detailed error codes (WSAGetLastError).
|
|
|
|
|
If i call WSAGetLastError() after the connect function fails it returns a 0. I dont know what that suggests though... What other detailed error codes can i find in my program?
How would I convert the code i linked to above into a open connection type?
Or maybe there is some example code of open TCP connection on codeproject?
//Johannes
|
|
|
|
|
Johpoke wrote: If i call WSAGetLastError() after the connect function fails it returns a 0. I dont know what that suggests though... What other detailed error codes can i find in my program?
Morning Johannes, maybe the error occurs earlier in your source code, check function return codes.
Johpoke wrote: How would I convert the code i linked to above into a open connection type?
Which code, sorry I don't understand what you mean.
/M
|
|
|
|
|
Hey, just a quick question about your requirements: Do you want to send 64 bytes from client to server without a response in regular intervalls... or the other way around where the server sends data to every incoming client?
|
|
|
|
|
The server (which binds to port 23) is listening to incoming clients, and as soon as one connects, it sends the 64 characters, and then disconects the client, waiting for a new one.
So the second way in you message.
But yea, the server doesnt need to know anything really, just send the string upon new client. (the server doesnt have any idea when i cleint is coming either (ie in what interval)
When i was testing it a few mins ago, the interval was Sleep(50);
Thanks!
//Johannes
|
|
|
|
|
Hej, with this requirements I would use a design like this:
- server delivers data when a client connects or sends a (zero) byte
- server closes connection only if there's no activity for 3 seconds or network/send error
- server closes connection after a persistent connection stayed 60 seconds
- server has an upper limit of x incoming sockets (more will be ignored)
- clients stay connected and may request data repeatedly
- clients close connection in case of network/receive/send error
- clients close connection if the received data was not according to protocol
- clients automatically reconnect only if they have been sucessfully connected and identified a server in last attempt
- clients could do multiple reconnect attempts, but with a delay (e.g. 60 seconds) and an upper limit of x reconnect attempts
This should give you a fairly efficient use of TCP and clients do not flood the LAN by error. Since you are using the telnet port on your server you could also use newline as a delimiter, which allows you do test with a telnet client.
|
|
|
|
|
Hello,
i have problems connection my webcam. I usw the video for windows (vfw.h).
Sometimesit works, i can see the live view and sometimes it doesnt work.
I have a main dialog and a setup dialog. when i push "setup" my setup dialog appears.
There, the use can choose the driver. I get the drivers by
<br />
for(int i = 0; i < 9; i++)<br />
{<br />
if(capGetDriverDescription(i,sName.GetBuffer(),sName.GetAllocLength(),<br />
sVersion.GetBuffe(),sVersion.GetAllocLength()))<br />
{ <br />
m_Drivers.Add(sName); <br />
}<br />
}<br />
in my main dialog there is a picture control element.
with GetClientRect i get the rect of this control and
fix it with ScreenToClient(&rect);
After that the InitCamera function is called.
<br />
void CUSBCamera::InitCamera(HWND HParent, int iDriverID, DWORD dwWidth, DWORD dwHeight, CRect rect)<br />
{<br />
m_hwndCap = capCreateCaptureWindow("USB-Camera",WS_CHILD | WS_VISIBLE,rect.TopLeft <br />
().x,rect.TopLeft().y,rect.Width(),rect.Height(),m_ParentWindowHandle,999);<br />
<br />
m_ParentWindowHandle = HParent; <br />
m_iDriverID = iDriverID;<br />
m_dwWidth = dwWidth;<br />
m_dwHeight = dwHeight;<br />
m_Rect = rect;<br />
<br />
capSetCallbackOnError(m_hwndCap, NULL);<br />
capSetCallbackOnCapControl(m_hwndCap,NULL);<br />
capSetCallbackOnStatus(m_hwndCap, NULL); <br />
capSetCallbackOnFrame(m_hwndCap, NULL); <br />
capSetCallbackOnVideoStream(m_hwndCap, NULL);<br />
capSetCallbackOnCapControl(m_hwndCap, NULL); <br />
capSetCallbackOnWaveStream(m_hwndCap, NULL);<br />
capSetCallbackOnYield(m_hwndCap, NULL);<br />
}<br />
Finished that, the connect function is called
<br />
BOOL CUSBCamera::Connect(LPFRAME_CALLBACK_PROC lpFrameCallback, LPVOID userData)<br />
{ <br />
if(capDriverConnect(m_hwndCap,m_iDriverID) && m_iDriverID >= 0)<br />
{<br />
capSetCallbackOnFrame(m_hwndCap,lpFrameCallback); <br />
capSetUserData(m_hwndCap,userData);<br />
<br />
DWORD dwSize; <br />
dwSize = capGetVideoFormatSize(m_hwndCap);<br />
m_lpbi = (LPBITMAPINFO)malloc(sizeof(BITMAPINFO)); <br />
<br />
<br />
capGetVideoFormat(m_hwndCap, m_lpbi, dwSize); <br />
m_lpbi->bmiHeader.biWidth = m_dwWidth;<br />
m_lpbi->bmiHeader.biHeight = m_dwHeight;<br />
<br />
capSetVideoFormat(m_hwndCap,m_lpbi,dwSize); <br />
<br />
capDriverDisconnect(m_hwndCap);
capDriverConnect(m_hwndCap,m_iDriverID);
<br />
capPreviewRate(m_hwndCap,100);<br />
capPreview(m_hwndCap,TRUE);<br />
<br />
<br />
free(m_lpbi);<br />
}<br />
else <br />
{<br />
::MessageBox(NULL,_T("Es ist ein Fehler aufgetreten"),_T("Fehler"),MB_OK);<br />
::DestroyWindow(m_hwndCap);<br />
return FALSE;<br />
}<br />
return TRUE;<br />
}<br />
My problem is, when i press update in my setup dialog i can choose just one driver.
Its the Windows WDM Capture (Win32).
Then i choose this driver press the apply button and i return back to the main dialog.
Well sometimes i see a picture from my webcam and sometimes its just black. i dont see anything.
Is there a certain order to initialize the camera ? And why do I have only just one driver in my list ? My graphicscard has a video in/out interface.
This makro capDlgVideoSource doestn work. With other applications i can connect to my webcam.
But with my try it's just a matter of luck getting access to it or not.
Well, one or two times it worked and i got this dialog. But choosing my webcam from the list
didnt change anything. Still had this black window i've created with capCreateCaptureWindow
If possible i want to avoid using the capDlgVideoSource dialog.
Please help me.
|
|
|
|
|
Hello again
i found out something interesting (well, for me it is).
I started a new simple project using th vfw interface.
But this time i also used capDlgVideoSource.
This time i could choose between my webcam and my video in from graphicscard.
And it worked. I got the view from my webcam. The interesting thing is, if i
choose my ATI video in from the capDlgVideoSource Dialog, close this program
and choose a driver in the actually program i dont see anything. Everthing is black.
When i start the programm where i use capDlgVideoSource and choose my webcam, close the program
and then choose the driver from my actually program it works.
Is there anyway to choose the source without using this capDlgVideoSource ?
It seems just selecting the driver (Windows WDM Capture) isnt enough.
greetings
|
|
|
|
|
I'm not sure how this is going to work...
for(int i = 0; i < 9; i++)<br />
{<br />
if(capGetDriverDescription(i,sName.GetBuffer(),sName.GetAllocLength(),<br />
sVersion.GetBuffe(),sVersion.GetAllocLength()))<br />
{ <br />
m_Drivers.Add(sName); <br />
}<br />
}
How large are your string buffers? Which gets called first - GetAllocLength() or GetBuffer()?
If you must use CString like this, I would recommend calling GetBuffer() first with an appropriate length.
You also must release the buffer before using it...
for(int i = 0; i < 9; i++)<br />
{<br />
LPTSTR pNameStrBuff =
sName.GetBuffer(256);<br /> LPTSTR pVersionStrBuff =
sVersion.GetBuffer(256);<br />
<br /> BOOL fRet = capGetDriverDescription(i, pNameStrBuff , 256, pVersionStrBuff
,256);<br />
<br />
sName.ReleaseBuffer();<br />
sVersion.ReleaseBuffer();
if (fRet)<br />
{ <br />
m_Drivers.Add(sName); <br />
}<br />
}
As far as getting the video to work - debug it. Check the return values from those calls.
Where is it failing?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello thanks for your answer.
I dotn have problems getting the drivers. This always works.
And yes, i also use sName.GetBufferSetLength( ).
I found the problem but dont know how to solve it.
As i told in my first reply i said that i wrote another small dialog for testing.
<br />
m_sLiveview.GetWindowRect(&m_Rect);<br />
ScreenToClient(&m_Rect);<br />
m_hwndCap = capCreateCaptureWindow(_T("USB"),WS_CHILD|WS_VISIBLE,m_Rect.TopLeft().x,m_Rect.TopLeft().y,m_Rect.Width(),m_Rect.Height(),this->GetSafeHwnd(),999);<br />
<br />
CString szDeviceName; szDeviceName.GetBufferSetLength(100);<br />
CString szDeviceVersion; szDeviceVersion.GetBufferSetLength(100);<br />
CAtlArray<cstring> List;<br />
<br />
for (int wIndex = 0; wIndex < 10; wIndex++) <br />
{<br />
if (capGetDriverDescription (wIndex, szDeviceName.GetBuffer(), szDeviceName.GetAllocLength(), szDeviceVersion.GetBuffer(),szDeviceVersion.GetAllocLength()))<br />
{<br />
List.Add(szDeviceName);<br />
}<br />
} <br />
<br />
capDriverConnect(m_hwndCap,List.GetCount()-1);<br />
CAPDRIVERCAPS caps;<br />
capDriverGetCaps(m_hwndCap,&caps,sizeof(CAPDRIVERCAPS));<br />
<br />
CString sMCIName;<br />
if (caps.fHasDlgVideoSource)<br />
{<br />
capDlgVideoSource(m_hwndCap); <br />
}<br />
<br />
capCaptureAbort(m_hwndCap);<br />
capSetCallbackOnError(m_hwndCap,NULL);<br />
capSetCallbackOnCapControl(m_hwndCap,NULL);<br />
capSetCallbackOnStatus(m_hwndCap,NULL);<br />
capSetCallbackOnFrame(m_hwndCap,FrameCallbackProc);<br />
capSetCallbackOnVideoStream(m_hwndCap, NULL);<br />
capSetUserData(m_hwndCap,NULL); <br />
<br />
capPreviewRate(m_hwndCap,150);<br />
capPreview(m_hwndCap,TRUE);<br />
</cstring> ;
with this settings it works because i call the capDlgVideoSource makro. There I can choose between
my graphicscard input and my webcam. So i think i need a way to get the device names instead
of the driver name. Althouh i have to input device installed (graphicscard video input and webcam) i can only choose one Windows WDM Capture Driver.
I also checked out the capGetMCIDeviceName but this only gets the previously set MCI device name.
Do you understand my problem ?
greetings
|
|
|
|
|
Member 3509166 wrote: So i think i need a way to get the device names instead
of the driver name
AFAIK there's no way from VFW. From VFW's point of view, there's just one driver - the
WDM driver wrapping (for VFW) the devices that don't have VFW-specific drivers (very few devices provide
VFW drivers anymore - they're pretty much obsolete).
I stopped using VFW long ago, so I never looked into it, but there may be a way to manipulate
the driver but it would be through WDM, not VFW.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello Mark, thanks for your reply.
I've just read this at another forum. someone had the same problem as me.
this is a part from public paper from 1997
"An example of incomplete API functionality can be found in the video capture API. Although it is possible to set the video source using a dialog box displayed to the user by calling the capDlgVideoSource function, doing the same from within an application without user mediation is, as far as we know, impossible. "
if this is true, it has never been fixed.
My webcam works when i use the capDlgVideoSource dialog.
But i want it without this.
At this forum someone wrote that the wdm handles more devices. so for me that means i can connect to the driver but if i have more than one device theres no other way getting acces to my webcam using this cap dialog.
the cap functions seems really easy to handle for me
greetings,
Robert
|
|
|
|
|
I don't know what to tell you.
Support for VFW was dropped many years ago. It's still there to support
legacy applications and that's it.
Probably your only choices are:
1) let the user select the device from the diaolg. I've never seen a driver that didn't persist these
settings.
2) Use a more modern video acquisition method.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi.
Just curious if anyone knows an easy way to change the height of a CStatusBar?
Thanks in advance.
Stan the Man
|
|
|
|
|
Stan the man wrote: an easy way
Move your chair closer?
I haven't tried the following, but if you use CStatusBar::GetStatusCtrl, you can then use CStatusCtrl::SetMinHeight, which sounds like it should help.
The msdn example for it has it being used in the OnCreate method of it's parent, which is before everything gets finally positioned, so probably a good time.
Iain.
Iain Clarke appearing in spite of being begged not to by CPallini.
|
|
|
|
|
Hi Iain.
That did it.
Thanks.
Stan the man
|
|
|
|
|
Hi All,
I want to use CFtpConnection to download and upload some files to some server.
But i want to do it in asynchronous way.
What i mean is to give some function address and in the end of upload/download this function will be call.
How can i do it ?
Thanks.
|
|
|
|
|
Great job for a worker thread.
You could use CFtpConnection::GetFile()/CFtpConnection::PutFile() on a separate thread.
As always, for more control over the file transfers, you can use
CFtpConnection::OpenFile()/CInternetFile::Read()/CInternetFile::Write().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
|
|
Hello everyone,
For dllimport KB from Microsoft,
http://support.microsoft.com/kb/132044/en-us
It is mentioned,
--------------------
If 'func1' exists in another DLL, the linker can't resolve this directly because it has no way of knowing what the address of 'func1' is.
--------------------
My question is, if we are using implicit linking, the address of import function should be in the import library (.lib file) of the DLL and since the import library is as an input parameter to linker, the linker should know the address at link time?
thanks in advance,
George
|
|
|
|
|