Home > Software engineering >  How to run the program after the interface has been testing in the process of a network connection
How to run the program after the interface has been testing in the process of a network connection

Time:10-31

I want to in my application to join the following functions:

Such as the program runs after a process has been testing whether the network connection, when the network connection is detected after stop testing, and one of another CPP was written by the original "network not connected" changes into "network connected
"
How to implement this function,

First thanks for your brothers

CodePudding user response:

Open a thread of judgment

CodePudding user response:

Upstairs, the elder brothers can detailed, I am a novice, don't know much about it

CodePudding user response:

AfxBeginThread start new threads, thread to determine whether a socket is normal, abnormal when sending a message to another window

CodePudding user response:

//AfxbeginThread create a thread, the thread has been testing connection arrives, arrival notice UI updates, and exit the threads,

CodePudding user response:

In functional design, program structure is divided into: master, communications and other modules, each module belong to different threads, through the custom message communication between modules, connection after the completion of the communication module, sending a message to the master, master can be connection status display processing,

CodePudding user response:

Use of heartbeat packets,

CodePudding user response:

Thanks for brother's answer, I first baidu AfxbeginThread, for example, see can solve,

CodePudding user response:

Thread this thing, is to develop desktop web applications,

CodePudding user response:

AfxbeginThread should add in where, how to detect whether the network connection, how to notify another CPP words ah, a little dizzy

CodePudding user response:

Do you have any brothers can give one example, really don't know where should be added

CodePudding user response:

Network connection is successful or disconnect system will automatically give event messages, as long as the handling of the incident, what need to use a "process" to monitor? On receipt of the connection is successful message event processing, display the connection is successful, I set up the connection is successful in the program that is successful, notify the main program in the interface display "equipment connected" :
 
if(! M_ClientSocket - & gt; The Connect (m_defaultIP m_defaultPort))//connection specified address, port
{
//client connection failure
SocketReset ();//release the allocated space, subroutine emptied m_Connect string
//to reconnect, reset the state machine
M_netState=S0;
NetCommState (ev_conn);
}
The else
{
//the connection is successful, create traffic
M_file=new CSocketFile (m_ClientSocket);
//the connection is successful, inform the master control program
NetCommState (ev_conn_ok);
}

CodePudding user response:

Haven't on BBS, this feature also hasn't been implemented, today I try again

CodePudding user response:

Which Internet connection do you mean with a computer to connect? Lower right corner of the screen or the "without a network connection" icon? What kind of situation, each has different solutions

CodePudding user response:

The
reference 13 floor gencheng reply:
which Internet connection do you mean with a computer to connect? Lower right corner of the screen or the "without a network connection" icon? What kind of situation, each has different solution


What I mean is to detect the network is connected, if you have outside network, showed that the connected, otherwise not connected,

CodePudding user response:

On the 14th floor awfymwvf
reference response:
Quote: refer to the 13th floor gencheng response:

Which Internet connection do you mean with a computer to connect? Lower right corner of the screen or the "without a network connection" icon? What kind of situation, each has different solution


What I mean is to detect the network is connected, if you have outside network, showed that the connected, otherwise not connected,

Ping www.baidu.com?

CodePudding user response:

Do you have any good solution

CodePudding user response:



 
The SOCKET sockClient=SOCKET (AF_INET, SOCK_STREAM, 0);

//connect server socket
SOCKADDR_IN addrServer;
AddrServer. Sin_addr. S_un. S_addr=inet_addr (" 192.168.1.1 ");
AddrServer. Sin_family=AF_INET;
AddrServer. Sin_port=htons (80);

If (connect (sockClient, (SOCKADDR *) & amp; AddrServer, sizeof (addrServer))==SOCKET_ERROR)//connection specified address, port
{
MessageBox (NULL, _T (" client connection failure "), _T (" greetings "), 0).
}
The else
{
MessageBox (NULL, _T (" the client connection is successful "), _T (" greetings "), 0).
}


Thank you brothers, thank you very much,

CodePudding user response:

I found a piece of code, but why always prompt connection fails?

The
cited the 17th floor awfymwvf reply:
 
The SOCKET sockClient=SOCKET (AF_INET, SOCK_STREAM, 0);

//connect server socket
SOCKADDR_IN addrServer;
AddrServer. Sin_addr. S_un. S_addr=inet_addr (" 192.168.1.1 ");
AddrServer. Sin_family=AF_INET;
AddrServer. Sin_port=htons (80);

If (connect (sockClient, (SOCKADDR *) & amp; AddrServer, sizeof (addrServer))==SOCKET_ERROR)//connection specified address, port
{
MessageBox (NULL, _T (" client connection failure "), _T (" greetings "), 0).
}
The else
{
MessageBox (NULL, _T (" the client connection is successful "), _T (" greetings "), 0).
}


Thank you brothers, thank you very much,

CodePudding user response:

Try {
} the catch ()
The finally {
}

CodePudding user response:

Catch exceptions, looking at what the problem is.
  • Related