|
Say i have a client and server. Server listening at 10.10.10.10 on port 4000. Client connects from 11.11.11.11. Server sends back a message saying:
"You are connected from <ip> on port <port>"
Where having the server use GetPeerName would give the proper ip of 11.11.11.11, but the port will be some other number other than 4000 in my case. So the message to the client would say something like:
"You are connected from 11.11.11.11 on port 3000"
Should GetPeerName be returning 4000 as the port? Or is the port of the client just a random one?
|
|
|
|
|
Type: netstat -n
GetPeerName will return the "remote address" column (only a single item of course).
Don't try it, just do it!
|
|
|
|
|
Ok thanks. The client port is just a random one. I get it now.
|
|
|
|
|
I am starting a project soon and the contact wants to control the record volume settings from within the application. Is there a way to do this with sndvol32 or some other way without using DirectX? He is concerned about file size, that's why he doesn't wish to use DirectX. Thanks.
Bill Dennis
Orlando, FL
|
|
|
|
|
billiam904 wrote:
He is concerned about file size
Using DirectX does not create big binaries at all!
By the way: DirectX does adjust the volume of a single buffer, but not the volume of the system. You can use waveOutSetVolume to set the output volume.
Don't try it, just do it!
|
|
|
|
|
what would i use to set the Line In record level?
Bill Dennis
Orlando, FL
|
|
|
|
|
mixerSetControlDetails
Don't try it, just do it!
|
|
|
|
|
Hi,
I am quite new to vc++. I am doing a project in win32. I want to set timeout value for a while loop. I am checking a condition in a while loop. If that condition is not satisfied at all, instead of looping forever I want to set timeout value like 300 msec then exit the while loop. I want to do this with CreateEvent() and waitforsingleobject(), but I dont know how to do it exactly.
Can someone help me with sample code???
Thanks a lot.
|
|
|
|
|
You can't create an easy timeout loop that way. What kind of code is running in the loop? There are normally better ways.
Don't try it, just do it!
|
|
|
|
|
Actually inside the while loop I am reading or writing to a usb device using our library apis...what are the other ways doing it better.
|
|
|
|
|
Use completion routines and kinda timeout thread, that makes it easier.
Don't try it, just do it!
|
|
|
|
|
HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );<br />
<br />
while ( looping )<br />
{<br />
if( WaitForSingleObject( hEvent, 300 ) == WAIT_TIMEOUT )<br />
{<br />
}<br />
else<br />
{<br />
}<br />
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
That does not work because when there are more than 1 loop the timeout will be 300ms FOR EVERY LOOP, and not for the whole loop.
Don't try it, just do it!
|
|
|
|
|
Where was it mentioned that multiple loops were involved?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I don't know if this is a good way to do it but you could try something like:
DWORD t = GetTickCount();
while (1)
{
if ((GetTickCount() - t) > 300)
break;
}
|
|
|
|
|
Hi
I am using the library I found here:
http://www.codeproject.com/system/serial.asp
in my program. However, I run into the following problem when I am reading from a comport. (example listener).
I took the code, and created a little function
int readme(CSerial &serial)<br />
{<br />
LONG lLastError = ERROR_SUCCESS;<br />
lLastError = serial.SetMask(CSerial::EEventBreak |<br />
CSerial::EEventCTS |<br />
CSerial::EEventDSR |<br />
CSerial::EEventError |<br />
CSerial::EEventRing |<br />
CSerial::EEventRLSD |<br />
CSerial::EEventRecv);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port event mask"));<br />
<br />
lLastError = serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port read timeout."));<br />
<br />
bool fContinue = true;<br />
do<br />
{<br />
lLastError = serial.WaitEvent();<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to wait for a COM-port event."));<br />
<br />
const CSerial::EEvent eEvent = serial.GetEventType();<br />
<br />
if (eEvent & CSerial::EEventBreak)<br />
{<br />
printf("\n### BREAK received ###\n");<br />
}<br />
<br />
if (eEvent & CSerial::EEventCTS)<br />
{<br />
printf("\n### Clear to send %s ###\n", serial.GetCTS()?"on":"off");<br />
}<br />
<br />
if (eEvent & CSerial::EEventDSR)<br />
{<br />
printf("\n### Data set ready %s ###\n", serial.GetDSR()?"on":"off");<br />
}<br />
<br />
if (eEvent & CSerial::EEventError)<br />
{<br />
printf("\n### ERROR: ");<br />
switch (serial.GetError())<br />
{<br />
case CSerial::EErrorBreak: printf("Break condition"); break;<br />
case CSerial::EErrorFrame: printf("Framing error"); break;<br />
case CSerial::EErrorIOE: printf("IO device error"); break;<br />
case CSerial::EErrorMode: printf("Unsupported mode"); break;<br />
case CSerial::EErrorOverrun: printf("Buffer overrun"); break;<br />
case CSerial::EErrorRxOver: printf("Input buffer overflow"); break;<br />
case CSerial::EErrorParity: printf("Input parity error"); break;<br />
case CSerial::EErrorTxFull: printf("Output buffer full"); break;<br />
default: printf("Unknown"); break;<br />
}<br />
printf(" ###\n");<br />
}<br />
<br />
if (eEvent & CSerial::EEventRing)<br />
{<br />
printf("\n### RING ###\n");<br />
}<br />
<br />
if (eEvent & CSerial::EEventRLSD)<br />
{<br />
printf("\n### RLSD/CD %s ###\n", serial.GetRLSD()?"on":"off");<br />
}<br />
<br />
if (eEvent & CSerial::EEventRecv)<br />
{<br />
DWORD dwBytesRead = 0;<br />
char szBuffer[101];<br />
do<br />
{<br />
lLastError = serial.Read(szBuffer,sizeof(szBuffer)-1,&dwBytesRead);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to read from COM-port."));<br />
<br />
if (dwBytesRead > 0)<br />
{<br />
szBuffer[dwBytesRead] = '\0';<br />
<br />
printf("%s|", szBuffer);<br />
<br />
if (strchr(szBuffer,EOF_Char))<br />
fContinue = false;<br />
}<br />
}<br />
while (dwBytesRead == sizeof(szBuffer)-1);<br />
}<br />
}<br />
while (fContinue);<br />
serial.Close();<br />
lLastError = serial.Open(_T("COM1"),0,0,false);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
return 0;<br />
}
then, what I do is following:
int __cdecl _tmain (int , char** )<br />
{<br />
CSerial serial;<br />
LONG lLastError = ERROR_SUCCESS;<br />
<br />
lLastError = serial.Open(_T("COM1"),0,0,false);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
<br />
<br />
<br />
<br />
lLastError = serial.Write("\nwhoami\n");<br />
int r;<br />
<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
lLastError = serial.Write("\nwhoami\n");<br />
<br />
r = readme(serial);<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
<br />
<br />
if (lLastError != ERROR_SUCCESS)<br />
return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
<br />
serial.Close();<br />
return 0;<br />
}
ok when the first is commented out, I see the results of both functions. but when the first readme is there, it only reads up to that point, and goes no further.
why is that so? I would like to read information step by step, as it needs to processed.
thanks alot for any help
quarry
|
|
|
|
|
Hello,
Put the caret next to that line and than hit "run to cursor" in your Debug menu. Second step in your code and see where your code hangs and post more specific information on your problem. Until then, most people here will not bother to look at your post with so much code.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
hey thanks for the answer
if (strchr(szBuffer,EOF_Char))<br />
fContinue = false;
I think the problem is, that this never happens.
so it gets stuck in this while loop, where there is a function
lLastError = serial.WaitEvent();
but nothing happens here neither. how can interupt this loop?
thanks
|
|
|
|
|
Hello,
I think your problem is that you wait forever for an event. So I guess that no event arrives on your COM port and that you are stuck in the WaitEvent() function.
See if this helps:
lLastError = serial.WaitEvent(NULL , 100 );
if( lLastError == ERROR_TIMEOUT )
{
}
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi All,
Ive got a project which was developed in Visual C++ version 6.0.
Now Ive got to make it access a web service to get data from a database...
First of all im COMPLETELY ignorant on these matters, but i suppose we've all got to take the plunge sometime...
I know that in the Visual Studio .NET version there are some tools to "automatically" generate the volumes of code required to do the web service method accessing stuff, but I dont want to change to .NET just to do this little thing!
Is there a simple generalized web service accessing API which wraps all the crap required to access a web service into a few simple routines?
Ive been looking around the net but im not convinced that Ive found the perfect solution.
Thanks in advance for any pointers,
Dave
|
|
|
|
|
Search here on CP for an article by Anders Molin. It has a class that does exactly what you are looking for.
|
|
|
|
|
|
Now I am able to read data from a .rtf file and write its contents in a rich edit control. Now I want to include this .rtf file as a resourse (just like we include bitmap), to print its contents in a rich edit control. Please can anyone tell me how can i do that?
Thank you
Aqueel A. Mirza
We Believe in Excellence
|
|
|
|
|
Goto the resource pane: right click on the on the root node of the list and select import.
OR
Insert->Resource->Import
OR
Ctrl+R
You should be able to figure out the rest from there.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Here is a somewhat related example.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|