Application of Winsock technology in Remote Monitoring

Source: Internet
Author: User

Abstract: Based on Winsock technology and network communication principles, this paper uses VC ++ programming technology to obtain real-time temperature running graphics on the client through network data transmission, remote monitoring of the temperature running status of the artificial climate room is implemented to meet the real-time automation requirements of low cost and high efficiency.

Key words: Winsock socket; remote monitoring; artificial climate room; Data Transmission

  1 Introduction

With the continuous development of network technology, the network has had a profound impact on society. As a result, a new network-based monitoring and management framework emerged. Remote monitoring of network-based devices has become a hot topic in the field of computer network applications. The socket technology is used to achieve connections and data exchange between networks, and remote monitoring of devices.

  2 features and Implementation of the remote monitoring system of the artificial climate room

2.1 Communication Interface ----- socket Creation

What we need to achieve in this article is remote monitoring of a small artificial climate room, in a remote or within the same LAN, you do not have to visit the site to observe the current temperature conditions and operating temperature curves of the artificial climate chamber. Because the remote site only needs to query and observe, therefore, you only need to handle the communication and data transmission between the on-site monitoring computer and the remote client. In this way, the CPU processing time of the on-site computer is not used, which can save resources for more on-site processing work.

The connection to a remote server can be divided into the following processes:

(1) The service process is always started before the customer process. The service process first creates a socket.

(2) bind the local address to the created socket to mark the socket on the network.

(3) Place the socket in listening mode and prepare to accept connection requests.

(4) The client creates a socket and calls the socket function. The method is the same as above.

(5) The customer initiates a connection request to the server.

(6) When the request arrives, the accept () function of the blocked service process, as described in (3), generates a new socket to establish a connection with the client and return a receiving signal to the client.

(7) once the client socket receives a signal from the server, it indicates that the connection between the client and the server is ready and data can be transmitted.

(8) Close the socket. Once the task is completed, you must turn off the resources occupied by the released socket.

The code for creating a connection between the server and client is described as follows:

Server:

Void cserverview: onstart ()
{Started = true;
M_start.enablewindow (! Started );
Try
{G_slisten.create (6802, sock_dgram, null );
G_slisten.bind (6802, m_ip); //, 6802 indicates the port number, and m_ip indicates the Server IP address.
G_slisten.listen ();
(Cserverdoc *) getdocument ()-> g_pchatlisten = new cchatlsnsock (
(Canyserverdoc *) getdocument ());
Cchatlsnsock * g_pchatlisten = (canyserverdoc *) getdocument ()-> g_pchatlisten;
G_pchatlisten-> Create (9999, sock_stream); // create a socket for listening to a chat room
G_pchatlisten-> listen ();
Getdlgitem (idc_response)-> setwindowtext ("start to serve the client! ");
}

The running interface 1 after the server is enabled is shown in.

Client:

Void cclientview: onclientstart ()
{M_sockrecv.create (6801, sock_dgram, m_clientip); // 6801 indicates the port number and m_clientip indicates the Client IP address.
M_sockrecv.bind (6801, m_clientip );
M_timer1 = settimer (1,1000, null );
M_timer2 = settimer (2,250, null );
Getlocaltime (& systime );
M_starttime = policime;
M_waveplay.setstarttime (systime. wyear, systime. wmonth, systime. wday, systime. whour, systime. wminute, Iime. wsecond); // plot the initial time of the curve.
This-> m_currentpolicime.setfocus ();
}


Figure 1: enable the Service running interface on the server

2.2 network data transmission and monitoring implementation

In network-based remote control and measurement applications, the binary format is generally the main cluster type for data transmission. In the remote monitoring system of the human climate room, both parties need to transmit less data streams, generally, the lower computer is an embedded system such as a microcontroller. The data processing capability is slow, and the communication parties do not have to maintain close contact. Therefore, most of them adopt the UDP protocol, which is based on the point-to-point method, the data reliability of communication between the two parties can be ensured by defining the data representation format. In addition, the data transmitted over the network is re-painted and displayed on the client in the form of a curve, and a self-developed ActiveX control is used to display the received data, the delay in data transmission is very short and negligible.

When the device is running, the status of the server is always enabled. The temperature measuring component transmits the measured temperature value to the control microcomputer, transmits the measured temperature value to the remote client through the network, and remotely connects the device by entering the IP address of the server, enter the specified username and password to connect to the instance and implement remote monitoring.

After the connection is established, the client can receive the temperature value sent and display it in a curve:

Void cclientview: ondatareceive ()
{
Extern clistbox * pmylistbox;
Char sztemprecv [20];
Cstring szip (m_ip); // obtain the IP address of the server.
Uint uport = 6802; // indicates the port
Int itemprecv = m_sockrecv.receivefrom (szrecv, 10, szip, uport, 0 );
Szrecv [irecv] = '/0 ';
M_szrecv = sztemprecv;
M_listbox.addstring (lpctstr) m_szrecv );
Int ncount = m_listbox.getcount ();
If (ncount> 0)
M_listbox.setcursel (ncount-1 );
Getlocaltime (& systemtime );
M_nowtime = systemtime;
Cstring strpolicime;
Strpolicime. format (_ T ("% d-% d: % d"), systemtime. wyear, systemtime. wmonth, systemtime. wday, systemtime. whour, systemtime. wminute, systemtime. wsecond );
Updatedata (false );
Curabstime = (m_nowtime-m_starttime). gettotalseconds ();
M_waveplay.setpoint2 (curabstime, atoi (m_szrecv); // use a self-made ActiveX Control to draw a temperature curve

The running interface 2 is displayed on the remote logon page.

  3: Conclusion

In practical applications, the program also provides chat, remote screen viewing, and file upload and download functions to facilitate remote communication. In addition, the password and user name verification method are used for connection, which makes monitoring more powerful and prevents unauthorized users from logging on and tampering with data. In this paper, the artificial climate room is a project used for biological cultivation in cooperation with Shaoguan medical equipment factory. It has been put into use and is monitored by local area network.


Figure 2 Current temperature operation in the server's artificial climate room

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.