|
Hi,
I've 'ported' my client / server applicaton to Windows 7 32bit, but I can't get the client to connect to the server when they are both on the same machine (using address 127.0.0.1).
BUT, I can connect to the server on the XP machine using the client on the win7 machine across the LAN.
Or I can connect to the server on the win7 machine using the client on the XP machine.
Or I can connect to the server on the XP machine using the client on the same XP machine (using 127.0.0.1).
When I debug, there are no errors, and the servers blocks on accept() as normal.
I am totally at a loss to explain this or find a solution.
If anyone has any ideas, I'd love to hear them.
Thanks
|
|
|
|
|
are the server and the client running in separate processes?
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Yes. Separate processes. Both using Winsock2.
|
|
|
|
|
then i can only guess that there is a misconfiguration.
the server must be configured to listen to a certain port say 205 on the localhost (127.0.0.1).
the client must send messages to that same port (205) on the localhost (127.0.0.1)
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Thanks for your suggestion. The configuration seems to be OK. In any case, the port and IP is set correctly. Bizarrely currports show that the server is listening and that the connection is established on the client, but accept never unblocks.
I have now rewritten the client code using getaddrinfo() to request the socket and now it works. Inexplicably, it now works even though I am still connecting with the same socket and address.
I am curious to know why it works OK on XP but not Win7 in case I have future problems. I will post the server and client code snippets to see if you can see where the problem is.
Server:
err = WSAStartup( wVersionRequested, &wsaData );
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(port);
sock = socket(AF_INET, SOCK_STREAM, 0);
qtest = bind(sock, (SOCKADDR *)&sin, sizeof(sin));
result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &flag, sizeof(int));
...
test = listen(m_sock->get_sock(), 0);
m_sock->set_com_sock(accept(m_sock->get_sock(), (SOCKADDR *)&m_sock->get_sin(), &sinsize));
Client:
sin.sin_family = AF_INET;
WSAStartup(MAKEWORD(2,0), &WSAData);
sock = socket(AF_INET,SOCK_STREAM,0);
err = bind(sock, (SOCKADDR *)&sin, sizeof(sin));
err = connect(sock, (SOCKADDR *)&sin, sizeof(sin));
|
|
|
|
|
Without seeing some of your code it is difficult to offer any answers. However, I do not think there is an underlying Windows 7 problem as I have tested a similar configuration recently on my own Windows 7 system, and it worked without problems.
I must get a clever new signature for 2011.
|
|
|
|
|
Hi,
when i write the following, kindly guide me that the type of pointer *p and also the type(A or B) of object made in the same line (line 3).
Class A
{}
Class B : public A {}
main () {
A *p = new B; // line 3
}
|
|
|
|
|
Since p is declared as a type of A then the object returned from new will effectively be downcast to a type A object, so you will not be able to use any methods or properties unique to class B .
I must get a clever new signature for 2011.
|
|
|
|
|
However, he still could exploit polymorphism...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
downcast or upcast? A is at higher level in hierarchy.
|
|
|
|
|
aesthetic.crazy wrote: downcast or upcast?
You are casting from a derived class to a base class, and in English base is considered the lowest level, thus downcasting. I agree it's difficult because most diagrams give the impression that A (the base class) is at the top of the hierarchy.
I must get a clever new signature for 2011.
|
|
|
|
|
The type of the pointer is determined by the left hand side of the expression. The type of the created object is determined by the right hand side of the expression.
One interesting thing about C++ and C (to a lesser extent) is that when you declare a pointer you're not saying "this variable is a pointer to fixed class" but you're saying "this variable is a pointer to something with an interface of this type." In c this really only shows up when you convert to and from void * but in C++ it crops up a lot more (it's how C++ implements substitutability, AKA the Liskov Principle).
From this lot, when you write the expression:
A *p = new B;
you're saying two things to the compiler "p is a pointer to something with the interface of A" and "initialise that pointer with the address of a dynamically allocated B."
Cheers,
Ash
|
|
|
|
|
Some answers should have a "Really Good Answer" button.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Hi all i have developed a MFC Dialoag based application (server application TCP/IP communication a socket programming) on windows xp sp2.
I am getting application error message on one of the machine. but some other machine it is working fine. I am not able to fix this bug please help me .
The Error message is:
The instruction at "0x7c911948" referenced memory at "0x00000000".The memory could not be "read",
click on OK to terminate the program
click on CANCEL to debug the program
What error it is and how to fix it ?
Thanks in advance
|
|
|
|
|
It means your app tried to access memory using a null pointer.
To fix: Run your app under the debugger, check the call stack when it breaks.
|
|
|
|
|
how to check the call stack.
|
|
|
|
|
Should be down the bottom, but you can activate it via Debug>Windows>Call Stack
|
|
|
|
|
i am using vc++ 6.0
i am not able to get this option Debug>Windows>Call Stack
|
|
|
|
|
View > Debug Windows > Call Stack
|
|
|
|
|
A call stack is the bare minimum.
Steve
|
|
|
|
|
The other way out is click on 'CANCEL' button to debug.
Before that copy the source code on the machine where you get the above crash.
Open the project in visual studio and build the project in 'DEBUG' mode.
Now run the application and click 'CANCEL' button to debug when the above error occurs.
When OS asks for debugger to attache, provide the running instance of the visual studio, that will take you to the point where the access violation is raised.
|
|
|
|
|
this error because i am creating multiple thread using AfxBeginThread() see below
my code :
WSADATA wsaData;
WSAStartup(0x0101, &wsaData );
struct sockaddr_in stSockaddr_in;
struct sockaddr stSockaddr;
SOCKET sock;
fd_set readfds1;
FD_ZERO( &readfds1);
//create listening socket
sock = socket(AF_INET,SOCK_STREAM,0);//create socket
//sets the family,port and the addrees
stSockaddr_in.sin_family = AF_INET;
stSockaddr_in.sin_addr.s_addr = INADDR_ANY;
stSockaddr_in.sin_port = htons(9000)
//Use bind to establish the local association of the socket by assigning a local name to an unnamed socket
int nRet = bind(sock, (LPSOCKADDR)&stSockaddr_in, sizeof(struct sockaddr));//bind
//listen function places a socket a state where it is listening for an incoming connection
if(listen( sock, MAX_CONNECTS ) < 0)//listen
{
//listen error
return 0;
}
SOCKET ret_sock;
//accept the connection
ret_sock = accept(sock,&stSockaddr,NULL);
if(INVALID_SOCKET != ret_sock)
{
char szBuffer[MAX_BUF_LEN];
//to receive the configuration data
int iLength = recv( ret_sock,(char*) szBuffer, MAX_BUF_LEN, 0 );
szBuffer[iLength] = 0;
CString csBuffer;
int iLen = strlen(szBuffer);
WCHAR wcStr[MAX_DATA_SIZE];
memset(wcStr,'\0',sizeof(WCHAR)*MAX_DATA_SIZE);
mbstowcs( wcStr,szBuffer,iLen);
csBuffer.Format(L"%s",wcStr);
////////////////////////////////////////////////////////////////////////
if(!csBuffer.IsEmpty())//data is not empty
{
CWinThread *Thread = NULL;
Thread = AfxBeginThread(func,(LPVOID)&someValue,THREAD_PRIORITY_NORMAL,0,0,NULL); //Here only i am getting the apllication error (Not Creating Multiple thead)
}
}
How to resolve this problem ?
|
|
|
|
|
To fix: Run your app under the debugger, check the call stack when it breaks.
|
|
|
|
|
it breaks in afxBeginthread creation only?
|
|
|
|
|
Why does it break?
What source line does it break on? What module?
If it breaks because of an assert, what does the assert statement say?
If it breaks because of a null pointer, what is the pointer supposed to be pointing to?
How do you expect us to help you when you don't give us all the details?
|
|
|
|