|
Now, I code a program that manage PCs by using TCP with CSocket class.
However when I check on console by shell command,
"netstat -na"
I can see the server and client is connected like as,
163.152.216.228:9000 163.152.216.70:1234 ESTABLISHED
163.152.216.70:1234 163.152.216.228:9000 ESTABLISHED
But, when I send a message on the server or the client,
the two do not get a message. Also, don't occure the OnReceive() events.
So, I tried it on debugging mode and checked that
the "Send" Function had the correct values and run exactly.
What is the problem ?
How can I solve it ?
Please, help me~
Always beside you,
Focused on Focus KWON
|
|
|
|
|
Hi
You mean to say you have written your server and client from derived class of CSOcket rgt ?
If so can you give me more details ?
Is your server dialog based or console application ?
If its a dialog based one then OnReceive() will run - no problem
If its a console aplication then OnReceive() will not receive from client because you need to TranslateMessage() and PeekMessage() which you can do by using a hidden CFrameWnd class .This is a known problem because in a console app the message handlers are not active by default .
So usually , most servers are written with Win32 socket APIs . Its not advisable to use CSocket for a server - but client is ok
redindian
|
|
|
|
|
Focus KWON wrote: How can I solve it ?
This library makes sending recieving a breaze. Network Development Kit 2.0[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
Hi
All
I want to use LoadStringResource() function in DLL. When i used this function in DLL code there is error as undeclare indentifier. Is there need to include any .H file to use it.plz send me info abt how to use LoadStringResource function.
Thnaks
Atool
M.Atul
|
|
|
|
|
The API is called LoadString()
|
|
|
|
|
Can any one guide me how do I monitor / check the health of a hard disk ?
I have gone through the msdn but I could not find in MSDN. My program is targettd to run on windows XP pro/2000 pro.
I found VDS interfaces for this functionality but they are only supported by Windows Vista.
can you please help me on this?
haribabu
|
|
|
|
|
kasturi_haribabu wrote: I have gone through the msdn but I could not find in MSDN. My program is targettd to run on windows XP pro/2000 pro.
look for WMI classes.. they have treasure hidden under them for this type of stuff
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
See here[^] if its helpfuls?
|
|
|
|
|
Hi everyone,
There is a need of embedding an application in an application, is there anyway? I mean I write an application and then I call CreateProcess to start a new application, all that I need is the new application will run in the window of my application.
Thanks in advance.
|
|
|
|
|
TPN wrote: There is a need of embedding an application in an application, is there anyway? I mean I write an application and then I call CreateProcess to start a new application, all that I need is the new application will run in the window of my application.
look some thing like containers.. read more about COM servers and DLLS
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Thanks for your reply.
I would like to clarify that the first application is mine and I write it but the second application that I need to call is not mine, it is any other existing application...
|
|
|
|
|
Can anyone help me in finding out the speed (kbps ) of the connection .
I need to calculate the time required for an upload depending on file size and the network speed . I am unable to find any documentation on it .
Is anyone aware of how to get this speed programmatically in VC++ ?
Thanks In Advance
--Vijayeta
|
|
|
|
|
vijayeta wrote: Is anyone aware of how to get this speed programmatically in VC++ ?
try IPhelper Apis
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
vijayeta wrote: Is anyone aware of how to get this speed programmatically in VC++ ?
look here for more http://www.codeproject.com/internet/IPHelper.asp
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Try to download a sample file using connection. File size/ time taken will give you the bandwidth. This is not accurate. Consider network latency & other factors
|
|
|
|
|
|
I want to customize the rebar's appearance(gripper, background...).I catch the NM_CUSTOMDRAW notification to do some processing, For example:
BOOL CMyReBar::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult )
{
.........
NMHDR* pNMHDR = ( NMHDR* )lParam;
switch ( pNMHDR->code )
{
case NM_CUSTOMDRAW:
{
//DWORD dwStyle = GetDrawStyle();
//if (dwStyle>DRAW_ORIGINAL)
*pResult=DoCustomDrawXP(pNMHDR);
break;
}
...........
}
........
}
LRESULT CMyReBar::DoCustomDrawXP( NMHDR* pNMHDR)
{
LPNMCUSTOMDRAW lpNMCustomDraw = ( LPNMCUSTOMDRAW )pNMHDR;
LRESULT pResult = CDRF_DODEFAULT;
switch ( lpNMCustomDraw->dwDrawStage )
{
case CDDS_PREPAINT:
pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
//here I try to owner-draw the rebar control's appearance
DrawItem(lpNMCustomDraw);
pResult = CDRF_SKIPDEFAULT;
break;
}
return pResult;
}
But I find in this way I can only custom-draw the gripper. If there is a chevron button on the rebar, it is disappeared. How could I get the similar notification to draw the chevron button by myself?
Thanks
Benben
|
|
|
|
|
I am trying to develop a C++ socket object. This object will be initialized as client or server. After the client is initialized with server ip address and port number I want to create a thread and have the thread maintain the socket connection and report the sockets client state.
I am having difficult try to find out if the client socket status. Whether the client socket is connected after i call connect() and whether the client socket has been disconnected after a connection has been made. What is the best way to check the status of the client socket.
*********************************************************************************************
Function Name:
Purpose:
**********************************************************************************************/
void SocketLib5::RunClient(void)
{
int eResults;
int state = INIT_CLIENT;
//int iOptVal;
int iOptLen = sizeof(int);
bool bOptVal;
int bOptLen = sizeof(bool);
int iMode;
hostent* localHost;
char* localIP;
/*do something*/
while( isRunning )
{
// Checks to see in system in initialized
switch( state )
{
case INIT_CLIENT:
// Starts up the socket interfaces, library, and dlls
eResults = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( eResults != NO_ERROR ){
WSACleanup();
break;
}
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr( server_ip );
server_address.sin_port = server_port;
localHost = gethostbyname("");// Get the local host information
localIP = inet_ntoa (*(struct in_addr *)*localHost->h_addr_list);
client_address.sin_family = AF_INET;
client_ip = localIP;
state = CREATE_CLIENT;
break;
case CREATE_CLIENT: // Creates a socket
client_socket = socket(client_address.sin_family, SOCK_STREAM, PPROTO_TCP );
if ( client_socket == INVALID_SOCKET ){
closesocket(client_socket);
state = INIT_CLIENT;
break;
}
// Disable Blocking Mode function calls
//iMode = 0;
//ioctlsocket( client_socket, FIONBIO, (u_long FAR*) &iMode);
state = INIT_EVENT_CLIENT;
break;
case INIT_EVENT_CLIENT: // Configures Status Events
bOptVal = true;
//bOptLen = sizeof(bool);
// eResults = setsockopt(client_socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&bOptVal, bOptLen);
// Create new event
g_hClientEvent = WSACreateEvent();
if (WSA_INVALID_EVENT == g_hClientEvent)
{
closesocket( client_socket );
state = INIT_CLIENT;
break;
}
eResults = WSAEventSelect(client_socket, g_hClientEvent, FD_READ | FD_WRITE | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
if ( eResults == SOCKET_ERROR)
{
WSACloseEvent(g_hClientEvent);
closesocket(client_socket);
state = INIT_CLIENT;
break;
}
state = CONNECT_CLIENT;
break;
case CONNECT_CLIENT: // Accepts Server Socket
eResults = connect( client_socket, (SOCKADDR*) &server_address, sizeof(server_address) );
if( eResults == SOCKET_ERROR ){
state = INIT_CLIENT;
eResults = WSAGetLastError();
switch( eResults )
{
case WSAEWOULDBLOCK:
state = LOOP_CLIENT;
break;
case WSAEISCONN:
state = LOOP_CLIENT;
break;
default:
state = INIT_CLIENT;
cout << " connect error " << eResults <<endl;
closesocket(client_socket);
="" break;
="" }
="" }else{
="" state="LOOP_CLIENT;
" }
="" break;
="" case="" loop_client:=""
=""
="" eresults="WSAGetLastError();
" switch(="" )
="" {
="" wsaewouldblock:
="" wsaeisconn:
="" break;
="" default:
="" cout="" <<="" "="" connect="" error="" <<endl;
="" wsaenumnetworkevents(client_socket,="" g_hclientevent,="" &networkclientevents);
="" switch="" (="" networkclientevents.lnetworkevents="" fd_write:
="" printf("write="" message:="" \n\r");
="" fd_read:="" printf("client="" read="" fd_accept:
="" printf("accept="" fd_connect:
="" connected="" fd_close:="" connection="" lost:="" }="" switch
="" isrunning="" while="" loop
="" wsacloseevent(g_hclientevent);
="" closesocket(client_socket);="" wsacleanup();
="" return;
}
=""
<div="" class="ForumSig">Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
From the time you get a FD_CONNECT to the time you get a FD_CLOSE or a recv() call returns 0
the socket is connected.
I don't see in your code where you are waiting for an event. Using a wait function is much more
efficient than polling and WSAEnumNetworkEvents() should be used only when an event occurs.
Which part are you having a problem with?
Mark
|
|
|
|
|
In my code within switch case LOOP_CLIENT, I poll for events. I am getting a FD_CONNECT event but I know the clientsocket is not connected. In fact the server socket application is not even running yet. I was hoping that I would only get a FD_CONNECT event after the client socket connected with server socket, and a FD_CLOSE after a connection has been broken.
Right now, i can not garantee that which socket will be running first. So, i need some way to find the status of the client socket and possibly cancel/restart the connetion attempt.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
I should have qualified that with "a successful" FD_CONNECT.
Check for an error:
WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
switch ( NetworkClientEvents.lNetworkEvents )
{
...
case FD_CONNECT:
if (0 != NetworkClientEvents.iErrorCode[FD_CONNECT_BIT])
printf("Connect Failed Message: \n\r");
else
printf("Client Connected Message: \n\r");
break;
...
}
Out of curiosity, why would you poll if you are using an event? It just needlessly eats CPU time.
|
|
|
|
|
Thanks Mark, that seem to work! I found in the MSDN that a FD_CONNECT error can be used to extract more information but, i am have not had success getting that information. I am guessing that FD_CONNECT_BIT is the indexing for the 10 array element of iErrorCode. Where can i find the other meanings of the array elements.
Additional error codes can be set when an application window receives a message. This error code is extracted from the lParam in the reply message using the WSAGETSELECTERROR macro. Possible error codes for each network event are listed in the following table.
Event: FD_CONNECT
Error code Meaning
WSAEAFNOSUPPORT Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED The attempt to connect was rejected.
WSAENETUNREACH The network cannot be reached from this host at this time.
WSAEFAULT The namelen parameter is invalid.
WSAEINVAL The socket is already bound to an address.
WSAEISCONN The socket is already connected.
WSAEMFILE No more file descriptors are available.
WSAENOBUFS No buffer space is available. The socket cannot be connected.
WSAENOTCONN The socket is not connected.
WSAETIMEDOUT Attempt to connect timed out without establishing a connection.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: I am guessing that FD_CONNECT_BIT is the indexing for the 10 array element of iErrorCode. Where can i find the other meanings of the array elements.
Correctemundo. In the platform SDK, Windows Sockets 2, under WSANETWORKEVENTS struct:
iErrorCode
Array that contains any associated error codes, with an array index that corresponds to the
position of event bits in lNetworkEvents. The identifiers FD_READ_BIT, FD_WRITE_BIT and others
can be used to index the iErrorCode array.
They were too lazy to list them
ScotDolan wrote: Additional error codes can be set when an application window receives a message. This error code is extracted from the lParam in the reply message using the WSAGETSELECTERROR macro.
That would be if you were using windows-based events (WSAAsyncSelect) I believe.
Since you are using WSAEventSelect, you get the error messages codes from the WSANETWORKEVENTS struct.
Mark
-- modified at 18:35 Monday 22nd January, 2007
|
|
|
|
|
In my post above I stated "Since you are using WSAEventSelect, you get the error messages from
the WSANETWORKEVENTS struct."
I forgot to mention that it only applies when WSAGetLastError() after a failed non-blocking
socket op returns WSAEWOULDBLOCK. Sometimes the error is reported immediately and you'll never
get the FD_xxx event.
Mark
|
|
|
|
|
For what i am learning, it seems like WSAAsyncSelect() with WSAGETSELECTERROR marco might be a better solution than WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
It seems that WSAAsyncSelect() will provide me with more information and less chance of missing a event.
A FD_CLOSE event produce the below error codes, but from what I understand if want to use WSAEnumNetworkEvents( ) I will not be able to get access to the below error message without a call to WSAGetLastError() and even that might miss a error code.
WSAEAFNOSUPPORT, Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED, The attempt to connect was rejected.
WSAENETUNREACH, The network cannot be reached from this host at this time.
WSAEFAULT, The namelen parameter is invalid.
WSAEINVAL, The socket is already bound to an address.
WSAEISCONN, The socket is already connected.
WSAEMFILE, No more file descriptors are available.
WSAENOBUFS, No buffer space is available. The socket cannot be connected.
WSAENOTCONN, The socket is not connected.
WSAETIMEDOUT, Attempt to connect timed out without establishing a connection.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|