|
how to set send & recv timeout for TCP?
|
|
|
|
|
|
Try changing the Socket.Blocking Property to false. That way when you call the connect method you can go into you're own loop counting the amount of time you want to wait, but, make sure the socket is on a seperate thread if it has to be or something to keep it working while you loop is working.
You could also try putting you're loop to sleep a number of milli-seconds or seconds to allow the socket to make its connection or not.
while( [it hasnt been 10 seconds] )
{
/* time code */
Threading::Thread::CurrentThread->Sleep( 1000 );
}
|
|
|
|
|
Use the appropriate WSAxxxxxx functions... FD_SETs and so on. Using threads and while loops is non-efficient in my opinion. And what do you exactly want to do ?? Is it a serving socket or a client one ? Why 10 seconds ? I can help more if you clarify your question.
|
|
|
|
|
Hi,
i need a high resolution timer for catching some packages on about every 20 msec.I already have working class which start multimedia timer with 1 msec. precision.And now,the problem: how to sen quit message to my Timer class,or is there any other way to stop the timer from main program in which Timer is started?
Generally, i would like to see some messaging issues in console app's, but with class approach and not classical c++.
many thanks
|
|
|
|
|
Has any body goten the new .net compiler in the toolkit to work with the VC++6 IDE??
How did you do it??
Thanks
|
|
|
|
|
I have a Windows Form Application (.NET), I am having trouble calling a procedure within the namespace from outside the namespace. I have the procedure displaychar outside the namespace which is a wrapper to be called from another programming language. The procedure showchar is within the namespace.
The code:
void displaychar(int mychar) //outside the namespace
{
//showchar(mychar);
formoutput::Form1::showchar(mychar);
}
--results in:
error C2653: 'formoutput' : is not a class or namespace name
Anyone have any ideas??
-Don
|
|
|
|
|
Mabye, formoutput really is not a namespace. I am figuring it may well be.
<br />
void displaychar(int mychar)
{<br />
Form1::showchar(mychar);<br />
}<br />
OR, You may not be including the header file ".\form1.h" witch should define the namespace <quote>formoutput. Use #include ".\form1.h" at the top of the source.
Then call it, however i bet you might get the error.
c:\Documents and Settings\default user.JOSH\My Documents\Visual Studio Projects\Tmle\mlr.cpp(105): error C2352: 'System::Windows::Forms::Form::showchar' : illegal call of non-static member function or something. If so, it means you must first create the class Form1 or gain a pointer to it when it is created from
<br />
Application::Run(new Form1());<br />
|
|
|
|
|
The subject basically says the gist of it.
I'm trying to write a program in C++ where it waits for input for up to 2 seconds but if nothing happens in 2 seconds, it stops looking for input and goes off to do something else.
I know this may touch on stuff that you need multi-threading for but I think I remember reading somewhere that there's a simpler way for something as simple as I'm looking to do.
Does anyone have any code snippets or any ideas?
Thanks in advance for your help.
MaKuTu t3h n00b
|
|
|
|
|
Probably more elegant to do this in a multithreaded fashion, but yes, it's possible to do what you want without multithreading.
First, you're going to need non-blocking input. If you don't have that, I think you're pretty much SOL.
Assuming you have non-blocking input, the basic logic is:
int granularity = 100;
int attempt = 2000;
int attempted = 0;
while (attempted < attempt)
{
if (inputIsAvailable())
{
doSomething();
}
else
{
Sleep(granularity);
attempted += granularity;
}
}
doSomethingElse();
|
|
|
|
|
I guess I don't know whether or not I have non-blocking input.
Do you know any examples of what a function like that might be called/what header file you need?
Thx
|
|
|
|
|
Not really. That would be entirely dependent on what libraries you ae using for input. Perhaps whatever library you are using provides a function (with a name such as bytes_available()) which returns the number of bytes currently available for access. I've used libraries (e.g. JNetLib) which has this type of functionality, but many libraries do not. It is possible to wrap an asynchronous APi and achieve this kind of functionality (which is what JNetLib does), but this wrapping will require threading.
It really depends on what you are trying to do, where this input is coming from, and what libraries you are using.
|
|
|
|
|
hi
i am kind of new in programming and am still learning c++ , and so far i know about functions arrays pointers and a little about file processing but no knowledge of object and classes...
anyway , i've been encountering some annoying problems , and i found out that they're all about the difference between the .h header files and the new ones with the 'using' and namespaces.
and here's some of the problems i found :
- when i use <iostream.h> and for example i store 025 in an integer with cin and then output it with cout i'll get a different value but with <iostream> and using namespace std; i dont have this problem
- while outouting and inputing to a file with <fstream> and using namespace std; and then passing this file to a recursive function as follows :
void func ( ifstream dd )
{ ..bla bla func(dd) bla bla.. }
...
ifstream file ("ff.txt");
func (file);
...
I get errors but with <fstream.h> i dont get these kind of errors
So if anybody would explain to me (in a simplified way) why i get these errors and if there's a way to do the same job with the new header files cause as you know in early courses they dont explain such things
And thanks
==<< ormax3 >>==
|
|
|
|
|
<br />
#include <iostream><br />
using namespace std;<br />
char a = 'a';<br />
int b = 38273;<br />
double c = 9382;<br />
char * d = "hello";<br />
cout << a << " " << b << " " << c << d << endl;<br />
---------------------------------------------------------------------------
<br />
#include "stdafx.h"<br />
#include <windows.h><br />
#include <iostream><br />
using namespace std;<br />
int main(int argc, _TCHAR* argv[])<br />
{<br />
char * OurBuffer = new char[2048];<br />
FILE * FileHandle;<br />
cout << "Reading from C:\\BOOT.INI, using a " <br />
<< ( sizeof(char) * 2048 ) <br />
<< " byte buffer." <br />
<< endl;<br />
cout << "Now displaying the file as it is read line by line." <br />
<< endl;<br />
FileHandle = fopen( "c:\\boot.ini", "r" );<br />
while( OurBuffer[0] != 0 )<br />
{<br />
OurBuffer[0] = 0;<br />
fgets( OurBuffer, 2048 * sizeof(char), FileHandle );<br />
cout << OurBuffer;<br />
}<br />
return 0;<br />
}<br />
---------------------------------------------------------------------------
<br />
Get a string from a stream.<br />
<br />
char *fgets( <br />
char *string,<br />
int n,<br />
FILE *stream <br />
);<br />
wchar_t *fgetws( <br />
wchar_t *string,<br />
int n,<br />
FILE *stream <br />
);<br />
Parameters<br />
string <br />
Storage location for data. <br />
n <br />
Maximum number of characters to read. <br />
stream <br />
Pointer to FILE structure. <br />
Return Value<br />
Each of these functions returns string. NULL is returned to indicate an error or an end-of-file condition. Use feof or ferror to determine whether an error occurred.<br />
---------------------------------------------------------------------------
<br />
Open a file.<br />
<br />
FILE *fopen( <br />
const char *filename,<br />
const char *mode <br />
);<br />
FILE *_wfopen( <br />
const wchar_t *filename,<br />
const wchar_t *mode <br />
);<br />
Parameters<br />
filename <br />
Filename. <br />
mode <br />
Type of access permitted. <br />
Return Value<br />
Each of these functions returns a pointer to the open file. A null pointer value indicates an error. <br />
----------------------------------------------------------------------------------------<br />
|
|
|
|
|
helloo...
this is my first post....
i wonder the differences between borland c++builder with c++ in general???
may you tell me where can i download trial version of borland c++ 6 enterprise edition??
thank's
any suggestion n answer is appreciated..........
|
|
|
|
|
I am trying to print from a richTextBox in Managed C++, but I can't figure out how to pront the formatting with the text. I tried making a streamreader and inputting the text, but I got an error that the streamreader can't be over 240 chars or something. I am also affraid that if I get this to work, it won't take into account all of the formatting. Hopefully someone can help.
James Meade
vLT(jg) vUSN
vOPSOFF VAQ-140
|
|
|
|
|
Hi Dear...
I struck in a problem & I know you can help me..
I've a pro-merchant account in amazon..& I want to upload Inventory to amazon.. but getting problem..File Error..even from site upload...
Can you send me Execl file you used for that uploading...
+ if possible some coding snippet of uploading invenorty. I want to upload through coding.. send me at:
sumit_kapoor1980@hotmail.com
or chat with me at hotmail account or yahoo: sumit_kapoor1980@yahoo.com
I hope you will help me..
Thanks
Have a Nice Life..
Sumit Kapoor.
---Sumit Kapoor---
|
|
|
|
|
Can any one tell me how can I detect keyboard whenever it is unplugged?
Any hint !!!
|
|
|
|
|
I need a good compiler... Preferably for Win32... I am noob..
|
|
|
|
|
|
Check out http://www.openwatcom.org
|
|
|
|
|
hi all,
i am doing a project which involves reading the message inside msm messenger
can someone have the idea how to get the text from the DirectUIHWND class in the msm conversation window
|
|
|
|
|
hi all,
here is my problem
i want to call a api(ReadFile) fucnction which return the byte array . how i have to declare and pass variables from managed c++.
|
|
|
|
|
There are two ways you can call ReadFile:
First way:
import the function:
[DllImport(S"Kernel32.dll", EntryPoint="ReadFile", CharSet=CharSet::Auto)]<br />
extern "C" Boolean ReadFileNative(IntPtr hFile,StringBuilder *lpBuffer,<br />
UInt32 nNumberOfBytesToRead,<br />
UInt32 *lpNumberOfBytesRead, <br />
Int32);
Here's a function that returns text from a file:
String *GetFileTextWithImport(String *fileName){<br />
FileStream *fs=new FileStream(fileName,FileMode::Open);<br />
HandleRef hRef=HandleRef(fs,fs->Handle);<br />
StringBuilder *sbText=new StringBuilder(fs->Length);<br />
UInt32 uiToRead=0;<br />
ReadFileNative(hRef.Handle,sbText,fs->Length,&uiToRead,0);<br />
fs->Dispose();<br />
return sbText->ToString();<br />
}
Second Way:
just call ReadFile without importing
String *GetFileText(String *fileName){<br />
FileStream *fs=new FileStream(fileName,FileMode::Open);<br />
HandleRef hRef=HandleRef(fs,fs->Handle);<br />
IntPtr ptrText=Marshal::AllocHGlobal(fs->Length);<br />
DWORD uiToRead=fs->Length, uiRead=0;<br />
ReadFile((HANDLE)hRef.Handle,ptrText.ToPointer(),uiToRead,&uiRead,NULL);<br />
String *strRet=Marshal::PtrToStringAnsi(ptrText);<br />
Marshal::FreeHGlobal(ptrText);<br />
fs->Dispose();<br />
return strRet;
P.S. By the way, why not use the System.IO.StreamReader?
|
|
|
|
|
thanx, _Ael
in my case i can't use StreamReader b'cos , I want Asyncronous function call. I am using ReadFile for RS232 port reading.
If we can use StreamReader or other managed call for asyncronous calls, then please let me know . how can i do the same.
|
|
|
|