|
Hello
I got a client/server solution where I use IOPORTS in the server.
Sometimes I get 10053 on WSASend/WSARecieve.
Why do I get 10053 in the server, and how do I resolve it?
Im not asking what the exact problem is, but to give me possible reasons that will help me to pinpoint the problem.
"An established connection was aborted by the software in your host computer, possibly due to a data transmission time-out or protocol error. " Doesnt help me that much.
|
|
|
|
|
check out this article, it may have a remedy for you.
*.*
|
|
|
|
|
Well. I think that the problem is that I do not disconnect correctly.
This is my code for disconnect:
if (m_nState == STATE_CONNECTED)
{
struct linger li = {0, 0}; // Default: SO_DONTLINGER
shutdown(m_sdClient, SD_BOTH);
setsockopt(m_sdClient, SOL_SOCKET, SO_LINGER, (char *)&li, sizeof(li));
}
closesocket(m_sdClient);
then i call acceptex:
if (!AcceptEx(*m_psdListen,
m_sdClient,
&m_wsaInBuf.buf[0],
SERVER_WORK_BUFFER_SIZE-(sizeof(sockaddr_in)+16)*2,
sizeof(sockaddr_in) + 16,
sizeof(sockaddr_in) + 16,
&dwBytesRecvd,
&m_ovIn))
{
if (GetLastError() != ERROR_IO_PENDING)
{
m_nState = STATE_DEAD;
closesocket(m_sdClient);
return;
}
}
Comments please.
|
|
|
|
|
oops. I do this before acceptex:
m_sdClient = socket(AF_INET, SOCK_STREAM, 0);
if (m_sdClient == INVALID_SOCKET)
{
m_nState = STATE_DEAD;
WriteLog(LI_HIGH, "Couldnt reinit a socket\n");
return;
}
DWORD dwBytesRecvd;
|
|
|
|
|
The client that connects to you needs to set their own linger options before they connect to you. Same with your server app (you should set linger before you bind the socket)..
I'm not sure if you can set that option after the socket has already been connected or after it accepts a connection..
One other thing (and im not 100% sure) but I dont think you need to call shutdown on a socket when it doesn't linger.. I think you can close the socket right away to free up the socket resoruces..
linger linger;
linger.l_onoff = TRUE;
linger.l_linger = 0;
setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(struct linger));
if(bind(server,(sockaddr*)&local,sizeof(local))!=0)
{
if(server != INVALID_SOCKET)
closesocket(server);
MessageBox("Error Binding socket", "Socket Error", MB_OK);
}
else
{
if(listen(server,10) != 0)
{
if(server != INVALID_SOCKET)
closesocket(server);
etc.....
}
Hope this gets you pointed in the right direction..
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Hi,
Is it possible to use different schema (version number) in the CDocument class ?
I know that I can do this with a different class with IMPLEMENT_SERIAL(), but CDocument is generate with IMPLEMENT_DYNCREATE() who do not use the argument for a different schema.
In fact can I change IMPLEMENT_DYNCREATE() to IMPLEMENT_SERIAL() in CDocument generate class ?
I utilize Visual C++ 6.0.
Thanks,
Claude Gagnon
|
|
|
|
|
The schema numbers in the serialization stuff is basically useless. What I have always done, and has worked well, is to write out my own version number in each class that is serialized. Then I can control things myself. EX:
void SomeClass::Serialize(CArchive & archive)
{
WORD wMagicNum;
WORD wVersion;
CObject::Serialize(archive);
if (archive.IsStoring())
{
archive << (WORD)0x444D;
archive << (WORD)1;
archive << m_cAlias << m_cDLLFileName << m_cDescription;
}
else
{
archive >> (WORD&)wMagicNum;
if (wMagicNum != 0x444D)
{
TRACE("Bad id number in front of a DLLModule item\n");
AfxThrowArchiveException(CArchiveException::generic);
}
archive >> (WORD&)wVersion;
archive >> m_cAlias >> m_cDLLFileName;
if (wVersion > 0)
archive >> m_cDescription;
m_bLoaded = FALSE;
m_hDLL = NULL;
m_pfnCallEntryPoint = NULL;
}
}
onwards and upwards...
|
|
|
|
|
I know I've been on the same problem for a day now, but I just can't get the numbers generated between a min and max value.
I really need to produce a double.
I have changed my function around 20 times and this is my latest try:
I had the function generating a number in the range of (min + 0.0~0.99999), but I need the range to sometimes reach close to the max or at least up to the middle.
the numbers that will be sent to the function are in the range of;
createRandNum(-2.8,4.8);
createRandNum(-15.0,126.0);
As you can see the range varies.
You guys always have the best solutions.
Thanks for the help,
Sj
<br />
double createRandNum(double min, double max){ <br />
<br />
<br />
double randomNum= rand();<br />
<br />
double p = ((max - min) + randomNum / (max-min)); <br />
double d = min + (double)rand() / RAND_MAX;<br />
<br />
<br />
while(count < 100){<br />
printf("%d\nRandomNum is: ", randomNum);<br />
printf("%d\nP is: ", p);<br />
printf("%d\nD is: ", d);<br />
count++;<br />
}<br />
<br />
return d; <br />
<br />
}
|
|
|
|
|
Try:
double result = ((double)rand() / RAND_MAX) * (max - min) + min;
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I get the same number each time.
When I try to cast the rand() function to a double I always get a 0.
I'm about to give up.
I sould probably spend my time writing a class that generates floats or doubles.
It seems like all the random generating classes only generate ints.
thanks for the try,
sj
|
|
|
|
|
Did you set the seed for rand()?
srand( (unsigned)time( NULL ) );
does this pretty well.
--
Ian Darling
|
|
|
|
|
johnstonsk wrote:
When I try to cast the rand() function to a double I always get a 0.
Which indicates something is off kilter. Mixing int and double in this fashion is not likely to produce the desired effect. I suggest rolling your own pseudo random generator.
A simple algorithm looks like:
static unsigned long ulSeed = 1;
#define A 48271L
#define M 2147483647L
double Random( void )
{
ulSeed = (A * ulSeed) % M;
return (double) ulSeed / M;
}
void Init( unsigned long ulVal )
{
ulSeed = ulVal;
}
Note that this could overflow. A fix by L. Schrage for 32-bit machines adds:
#define Q (M / A)
#define R (M % A)
double Random( void )
{
long lTempSeed;
lTempSeed = A * (ulSeed % Q) - R * (ulSeed / Q);
if (lTempSeed >= 0)
ulSeed = lTempSeed;
else
ulSeed = lTempSeed + M;
return (double) ulSeed / M;
}
|
|
|
|
|
Hmmm. That worked perfectly for me. This is the entire program I used to test it:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int __stdcall WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
srand((unsigned)time(NULL));
double max = 100.0f;
double min = 0.0f;
for(int i=0; i<20; i++)
{
char buf[128];
sprintf(buf, "%lf", ((double)rand() / RAND_MAX) * (max - min) + min);
MessageBox(NULL, buf, "test", MB_ICONINFORMATION | MB_OK);
}
return 0;
}
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
You are correct, it works great.
cheers,
sj
|
|
|
|
|
johnstonsk wrote:
it works great
Good
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Err...
while(count < 100){
printf("%d\nRandomNum is: ", randomNum);
printf("%d\nP is: ", p);
printf("%d\nD is: ", d);
count++;
}
This part of your sample code does nothing other than printing 100 times the same number 'randomNum'... you know that or?
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
Are there standard small (16x15) error and warning images that suitable for use in the report view of a list control. I have tried using the IDI_WARNING and IDI_ERROR resources but you end up with an image that looks like it has been resized from 24x24. The event viewer uses some so I guess they are available to any program once you know how to get at them!
Steve.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
There is always the sneaky way... open event viewer, press Alt+PrintScreen, open Paint, paste in the screen and copy the desired images and paste them into your bitmap resources in your project.
onwards and upwards...
|
|
|
|
|
|
basementman wrote:
the sneaky way
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Heylo. i've got myself a vector of strings, and i want the contents of the vector to end up in a combobox. here's my for statement:
for(int i = 0; i < values.size(); i++)
{
input_tq.AddString(values.at(i));
}
where input_tq is a combo box derived from CComboBox and values is a vector of strings.
this gives me the error that it cant convers my vector to LPCTSTR. (i assume this means its expecting a sting in quotes, not a vector?)
so, how can i fix this? i cant covnert the contents of the vector to individual strings because users can add to/delete from the vector.
|
|
|
|
|
this works for me.
AddString adds a string to the combo box, so passing individual strings in the vector is ok.
when the user adds and remove strings in the vector, you must also add/remove strings from the combobox as well.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
you mean you got that for loop to work? Here's the error statement i get:
error C2664: 'CComboBox::AddString' : cannot convert parameter 1 from 'std::allocator<_Ty>::value_type' to 'LPCTSTR'
with
[
_Ty=std::string
]
vector<string> values;
is how im defining my vector, im passing that into a function that reads into from a text file and passes it back by reference.
i replaced 'vector.at(i)' with "hello" and that works fine. it just doesnt like my vector of strings.
how does yours work and mine doesn't.
|
|
|
|
|
this is what I did :
...
std::vector<CString> stringVector;
stringVector.push_back("allo");
stringVector.push_back("bonjour");
stringVector.push_back("salut");
stringVector.push_back("bye");
for(int i = 0; i < stringVector.size(); i++)
{
m_ComboBox.AddString(stringVector.at(i));
}
...
if using std::string you get the string with std::string::c_str()
...
std::vector<std::string> stringVector;
stringVector.push_back(std::string("allo"));
stringVector.push_back(std::string("bonjour"));
stringVector.push_back(std::string("salut"));
stringVector.push_back(std::string("bye"));
for(int i = 0; i < stringVector.size(); i++)
{
m_ComboBox.AddString(stringVector.at(i).c_str());
}
...
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
excellent, my strings weren't null terminated. heh, rinky dinky c++ code...
thanks a bunch!
|
|
|
|