远程控制系统
远程信号控制系统

先修课程:
铁路信号基础、铁道概论、通信原理、计算 机网络、微机原理等。
考察方式: 总评成绩中,平时成绩占30%,期末考试占 70%。 考试一般采用闭卷笔试形式,题型为:填空、 简答、计算、分析设计等。
第一章 概 述
第一节 铁路运输调度的组织管理
DMIS:铁路运输调度指挥管理信息系统 我国铁路运输调度指挥管理是以行车调度为核心,实行铁道部、 铁路局、铁路分局三级调度管理的体制。 为适应现行的调度管理体制,并考虑到长远发展,铁路调度指 挥管理信息系统(DMIS)设计为四层网络体系结构。 1、最上层是部调度中心运输调度管理系统,是DMIS的核心。 它与铁路局调度中心远程连接,进行信息交换,并建立全路各 专业技术资料库。
(二)从实际需要出发,系统设计既要技术先进,又要经济合 理。 (三)系统工作的可靠性高,故障便于发现,易维修和更换部 件。只有这样才能保证设备正常使用,不影响运输任务的完成。 (四)系统设计时要通用化、系统化、灵活性大。调度集中、 调度表示设备、大站遥控遥信设备、大站遥信设备等都属于远动 系统。在设计时,各种设备的部件应该通用化,便于工厂生产。 灵活性主要表现在系统容量大,能适应各种区段的要求,个别情 况更改方便,容易扩展,适应性大。
列车运行图
技术计划
目的地
货 车 交 付
货主 车流
8
旅客运输生产过程图 始发地 旅客 旅客 列车
途中运行 换乘
目的地
铁路旅 客流
9
列车运行图:铁路行车组织工作的基础。
(1) 定义 列车运行图是用以表示列车在铁路区间运行及在车 站到发或通过时刻的技术文件,它规定各次列车占用区 间的程序,列车在每个车站的到达和出发(或通过)时刻, 列车在区间的运行时间,列车在车站的停站时间以及机 车交路、列车重量和长度等,是全路组织列车运行的基 础。
电器远程控制原理

电器远程控制原理
电器远程控制是利用无线通信技术和控制信号传输的原理实现对电器设备的远程操作。
它通常包括以下几个主要步骤:
1. 信号发送端的工作原理:信号发送端通常是一个控制设备,如遥控器或手机APP。
当我们按下遥控器上的按钮或在手机APP上点击相应的按钮时,控制信号会被发送到电器设备所在的地方。
2. 信号传输:控制信号通过无线通信技术进行传输,最常用的是无线电波传输。
遥控器或手机APP会将控制信号转化为相应的无线电波并发送出去。
3. 信号接收端的工作原理:信号接收端通常是电器设备上的一个接收器,比如红外接收器或无线接收模块。
当接收器接收到无线信号时,会将其转化为可以理解的电信号,并传递给电器设备的控制系统。
4. 电器设备的控制系统:电器设备上通常有一个控制系统,它会接收接收器传递过来的电信号,并根据信号的指令来控制设备的开启、关闭、调节等操作。
总的来说,电器远程控制主要通过信号发送端发送控制信号,通过无线通信技术将信号传输到信号接收端,然后由电器设备的控制系统根据接收到的信号指令来实现相应的操作。
这样,用户就可以在不同的地方通过遥控器或手机APP来远程控制电器设备。
供水系统远程控制

供水系统远程控制随着科技的不断进步,各行各业都在不断地探索着各种新技术,以提升效率和效益。
在城市的日常生活中,供水系统是不可或缺的一环。
为了更好地管理和调控市区供水系统,一种新的技术——供水系统远程控制技术也开始逐渐被广泛应用。
一、什么是供水系统远程控制?供水系统远程控制是一种通过远程通讯技术来实现对城市供水系统各个设备、仪器的遥控、遥测、遥调和传输信息的管理系统。
通过这种方式,可以实现对供水系统的实时监测和远程控制,以方便管理人员对供水系统的管理和调度,提高效率和减少成本。
二、供水系统远程控制技术的优势1. 实时监测:通过远程控制技术,可以对供水系统的各个参数进行实时监测,一旦出现问题可以及时进行调整和处理,让供水系统更加稳定和可靠。
2. 提高效率:传统的供水管理需要人工操作,存在效率低下和管理成本高的问题。
而通过远程控制技术,可以实现对供水系统的实时监测和远程控制,可以大大提高效率,节省时间和人力成本。
3. 降低维护成本:供水系统的管理和维护需要大量的人力和物力成本。
而通过远程控制技术,可以减少对供水设备的现场维护和人员巡检,降低了维护成本,并且也减少了人员因工作现场的危险和安全问题。
4. 智能化管理:远程控制技术可以实现对供水系统的智能化管理,通过数据分析和处理,可以更加精准地掌握供水系统的运行情况,提高监管的准确性和及时性。
三、供水系统远程控制的具体实践在实际应用中,供水系统远程控制技术已经得到广泛应用。
例如,在某市的供水系统中,通过建立中心控制室来进行远程控制。
中心控制室通过远程通讯技术可以实时接收供水系统的数据,包括水压、水量、水质等多个参数,情况,从而及时处理设备故障或异常情况。
此外,还可以通过中心控制室实现对供水系统的调度和管理,包括水流量的调整、阀门的开关、管网的疏通等功能。
通过这种远程控制技术,可以实现对供水系统的精细化管理,避免了传统的人工管理的问题。
四、供水系统远程控制的未来供水系统远程控制技术是一种新兴的技术,随着科技的不断发展和应用,这种技术将会得到越来越广泛的应用。
车联网安全揭秘车辆远程控制的风险与防护

车联网安全揭秘车辆远程控制的风险与防护随着科技的发展,车联网逐渐成为现代汽车的标配,为人们的驾驶生活带来了便利。
然而,随之而来的是车联网安全问题的增加。
本文将深入揭秘车辆远程控制的风险,并探讨有效的防护措施。
一、车辆远程控制的风险车辆远程控制是车联网的一项重要功能,让车主能够通过手机等远程设备控制汽车的各项功能,如解锁、启动发动机、空调调节等。
然而,这种便利也带来了一系列潜在的风险。
1. 黑客入侵风险车辆远程控制系统的普及使得黑客有可能通过网络入侵汽车系统,进行非法操控。
他们可以窃取车辆的敏感信息,如行驶轨迹、车主个人信息,并有可能控制车辆的刹车、加速等功能,对车主的安全构成威胁。
2. 软件漏洞风险车辆远程控制的实现依赖于车载设备的软件系统,而软件的漏洞给黑客提供了入侵的机会。
如果车辆制造商没有及时修补这些漏洞,黑客可以利用其进行非法操作,对车主和其他道路用户造成危险。
3. 数据注入风险远程控制系统的数据传输存在风险,黑客可能通过数据注入攻击,操纵车辆的控制命令。
这些恶意攻击可能导致车辆失控,引发交通事故,危及人们的生命安全。
二、车辆远程控制的防护鉴于车辆远程控制的风险,车主和制造商应采取一系列措施来保护车辆远程控制的安全。
以下是一些有效的防护策略:1. 加强网络安全制造商需要加强车辆远程控制系统的网络安全性能,确保网络传输的加密和认证。
此外,车主应定期更新车载设备的软件,不轻易连接未知或不安全的网络,避免给黑客入侵提供机会。
2. 提高用户安全意识车主应提高对车辆远程控制系统的安全意识,了解常见的网络攻击手段和防范措施。
他们应该警惕来自陌生号码或电子邮件的可疑信息,避免点击恶意链接或下载不明来源的应用程序。
3. 定期安全检测与更新制造商可以定期对车辆远程控制系统进行安全检测,并及时修复发现的漏洞。
同时,车主也应定期更新车载设备的软件,以获取最新的安全补丁和功能更新。
4. 强化车辆物理安全除了网络安全的防护,车主还应加强车辆的物理安全措施。
电脑系统的远程管理与控制

电脑系统的远程管理与控制在如今数字化快速发展的时代,电脑系统越来越成为我们生活和工作中不可或缺的一部分。
然而,对于那些拥有多台电脑的个人或者企业来说,如何高效地管理和控制这些电脑系统,却是一项巨大的挑战。
幸运的是,我们现在可以通过远程管理和控制来解决这个问题。
本文将为您详细介绍电脑系统的远程管理与控制技术,帮助您提高工作效率和便利性。
一、远程管理的定义和意义远程管理是指使用网络连接远程控制和监控电脑系统的一种技术手段。
通过远程管理,您不再需要亲自到每台电脑前进行操作,而是可以通过网络远程访问并控制电脑系统,实现统一管理和操作。
这项技术的意义在于方便性和效率的提升。
无论您身在何处,只要有网络连接,就能迅速操作和管理多台电脑,大大节省了时间和人力成本。
二、远程管理的应用场景远程管理技术在各个领域都有广泛的应用。
以下是一些常见的应用场景:1.企业办公:对于大型企业而言,拥有成百上千台电脑是常态。
通过远程管理,IT管理员可以在总部进行统一的电脑系统安装、维护和更新,而不用逐个前往每个分支机构或员工办公区。
2.教育机构:学校或大学通常拥有许多教学电脑。
通过远程管理,教师可以远程访问并控制学生电脑,方便课堂教学和学生学习。
3.家庭办公:对于居家办公的人群来说,通过远程管理可以实现在家办公的便利。
无论您身在何处,只需一台电脑或移动设备,就能轻松管理和控制您的工作电脑。
三、远程管理的技术方案目前市场上有许多远程管理软件和工具可供选择。
以下是一些常用的技术方案:1.远程桌面:远程桌面是指将远程电脑的桌面界面映射到本地电脑上,实现对远程电脑的控制。
借助远程桌面软件,您可以操作远程电脑上的文件、程序和设置,就像坐在远程电脑前一样。
2.远程终端:远程终端是指通过终端设备(如手机、平板电脑)远程连接到电脑系统,并进行管理和控制。
远程终端能够实现远程访问和操作,为用户提供了更多的灵活性和便利性。
3.远程协助:远程协助是指在远程情况下提供技术支持。
用Xmanager远程控制LINUX、UNIX系统X界面

用Xmanager远程控制LINUX、UNIX系统X界面从WINDOWS平台用Xmanager实现对LINUX,AIX等系统的控制,LINUX下X界面有GNOME(GDM)、KDE(XDM)、UNIX下X界面有CDE,GDM、XDM、CDE. 1. When I connect to UNIX by XDMCP, the CDE session hangs.1.1. I cannot see the login window.If you cannot see the loginwindow, you need additional fonts for the host. You can download andinstall the fonts in your Unix server or you can set up a font server.To run font server in host:Run "xfs&".Run "fsinfo -server host_IP_address:7100".To configure Xmanager:Start Xconfig in Xmanager2 folder.Open the properties of the profile for the session.Select Font tab.Add Font Server.Save the changes and run Xmanager.Also,one of the following reasons might prevent CDE connection to be made:The Unix server is not located in the same subnet with your PC.Your PC has multiple IP addresses.Name server has an invalid name-to-ip or ip-to-name entry for your PC. Check the forward andreverse lookup tables.See the /var/dt/Xerrors file for more detailed information.1.2. The CDE login window shows up. After login, the session hangs or is terminated. The $HOME/.dtprofile might have a line that prevents a successful login. You need to try to commentall commands out in the file. Also, remove the following lines in your login scripts.: export DISPLAY=:0.0orsetenv DISPLAY :0.0For more detailed reasons, please see $HOME/.dt/errorlog.以AIX5L为例,只要安装时选了图形界面,基本上可以连上CDE,不用做太多的的改动,若不行检查一下进程,防火墙,端口等2. XDMCP connection fails for Linux. How do I configure my Linux box?How to configure Linux XDMCP(KDE/GNOME) settings for XmanagerAffected FilesFor runlevel: /etc/inittabFor GDM: /etc/X11/gdm/gdm.confFor XDM: /etc/X11/xdm/xdm-config/etc/X11/xdm/Xaccess/etc/X11/xdm/kdmrc/usr/share/kdm/kdmrc/usr/share/config/kdm/kdmrc/etc/opt/kde2/share/config/kdm/kdmrcFor Firewall: /etc/sysconfig/ipchainsStep 1. Change runlevel to enable gdm or kdm.Open /etc/inittab file.Change the runlevel to 5 as following:id:5:initdefault:Step 2. GDM configuration (When the Linux is using gdm)若是以进程3登录的,又不想改成进程5图形登录,也可以在进去后动行GDM(gnome)或XDM(KDE),启动GDM、XDM进程Open /etc/X11/gdm/gdm.conf file.Go to the [xdmcp]section.Set the value of "Enable" option to "1".Step 3. KDM configuration (When the Linux is using kdm)Open /etc/X11/xdm/xdm-config file.Comment out "requestPort" option as following:DisplayManager.requestPort: 0==>!DisplayManager.requestPort: 0Open /etc/X11/xdm/Xaccess file.Remove the initial "#" character for the following line:#* #any host can get a login window==>* #any host can get a login windowOpen /etc/X11/xdm/kdmrc,/usr/share/config/kdm/kdmrc or/etc/opt/kde2/share/config/kdm/kdmrc file.Change the value of "Enable" option to "true".Step 4. Firewall configuration (If the firewall has been configured)Open /etc/sysconfig/ipchains file.Add the following lines at the top of the file:-A input -p udp -s 0/0 -d 0/0 177 -j ACCEPT-A input -p tcp -s 0/0 -d 0/0 telnet -j ACCEPT-A input -p tcp -s 0/0 -d 0/0 ssh -j ACCEPT-A input -p tcp -s 0/0 -d 0/0 login -j ACCEPT-A input -p tcp -s 0/0 -d 0/0 exec -j ACCEPT-A input -p tcp -s 0/0 -d 0/0 shell -j ACCEPT-A input -p tcp -s 0/0 -d 0/0 7100 -j ACCEPTStep 5. Restart your Linux to activate the changes.3. I am trying to connect to SUN Solaris/HP-UNIX/IBM AIX using XDMCP, but I get the error message:"XDMCP Connection failed."In order to use XDMCP connection, CDE login should be enabled on your remote server.Follow the instruction below to enable CDE login:Login as a root.Enable CDE login when system boot:$ /usr/dt/bin/dtconfig -e [enter]dtconfig -resetIf you want to disable the CDE login setting, do the following:$ /usr/dt/bin/dtconfig -d [enter]4. I’m in the local network inside a NAT system. How can I connect to the remote host?Torun a remote xterm program, your IP address should be a public one thatcan be reached from the remote host because a remote xterm tries toconnect to your local PC.If your PC is located inside the firewall or NAT and the Unix host is located outside, X applications cannot connect to the Xmanager running on your PC.There are two solutions on this situation:By configuring port forwarding rules on the NAT system.By using SSH protocol in the Xstart program.The two solutions above are only for Xstart connection, not for XDMCP. XDMCP connection is not supported currently.To use port forwarding, you should forward the port 6000 of NAT system to the port 6000 of your PC.In case of multiple local users, you can do the following steps:(NAT, 6001) ==> (PC1, 6000)(NAT, 6002) ==> (PC2, 6000)...(NAT, 600Array) ==> (PCArray, 6000)Then, in the Xstart program, each user have to enter "-display" option like this:/usr/bin/X11/xterm -ls -display $NATADDR:1The value of "-display" option should be:For PC1: $NATADDR:1For PC2: $NATADDR:2In case of using SSH connection, you do not have to configureother options. It establishes a secure tunnel between PC and Unix, sowe recommend you to use SSH protocol if the Unix server supports it.5. Which ports should I allow on my firewall?You should open the following TCP/UDP ports.From remote host to local PC (Inbound): TCP 6000 ~ 6010 for Xmanager*TCP 16001 for Gnome onlyFrom local PC to remote host (Outbound): UDP 177 for XDMCPTCP 512, 513, 514, 23, 22 for Xstart*Note: Gnome may fail to logout if TCP 16001 port is not allowed.6. I’m inside a firewall using IP masquerading. How can I connect to external Linux/Unix hosts?To use Xstart with IP masquerading, please do the following steps:run the following command as a root on your firewall server.# ipmasqadm portfw -a -P tcp -L firewall_address 6010 -R PC_address 6000run Xstart program.enter the following command at Command field./usr/bin/X11/xterm -ls -display firewall_address:10.0click the run button.Be sure that, firewall_address and PC_address must be changed to the corresponding IP addresses on your own network.7. How can I run a remote X application on my PC with a dynamic IP address?If you want to start an X application such as xterm, first click Xstart icon in the Xmanager folderand set the command field as following:"/usr/bin/X11/xterm -ls -display $DISPLAY"In the protocol field, you should select a protocol supported by your remote Unix/Linux server.8. How can I use Xmanager through SSH?Run Xstart in the Xmanager folder.Select SSH for Protocol.Enter username, password, hostname, etc.Type in Execution Command as following:/usr/bin/X11/xterm -lsNote that -display option is absent. SSH server will assign a proper value.Click Save and Run button.The Xstart will automatically run Xmanager and then execute the remote command. Array. When I open an xterm window, some characters are displayed incorrectly on the screen. Some (notall) capital letters looks like a small dot.Run Xconfig program in the Xmanager2 folder.Open the properties of the profile for the session.Select Advanced tab.Turn the Maximize performance option off.Save the changes and run Xmanager.10. I’ve lost my product key. Where can I find it?In the Customer Service page, you can find your product key. Click here.11. The Backspace key does not work in xterm from RedHat 7 host.run Keyboard Editor in Xmanager folder.open your keyboard file.click the BackSpace key you are using.change the keysym value as following:Unshifted: BackSpaceShifted: NoSymbolModeSwitch: NoSymbolShiftedModeSwitch: NoSymbolsave and restart Xmanager.12. How can I configure firewall settings in Windows XP/2003?Windows XP/2003 may block all incoming TCP/IP connections. So, Xmanager cannot be used without allowing its listening port.Please do the following steps to enable Xmanager connection.:Open Control Panel, Network and Internet Connection, and then Network Connections.Right-click on your Internet connection, and then click Properties.Click Settings. RESULT: Advanced Settings dialog box will open.Allow TCP port 6000 ~ 6010.If Windows XP Service Pack 2 is installed on your machine, follow the procedure below:Open Control Panel, and then Windows Firewall.From the General tab, select On (recommended) option.Click the Exception tab.Click the Add Program button.From the Programs list, select Xmanager - Passive.Click OK.13. Colors are not displayed correctly when I use 256-color CAD applications.Some old X applications using 256-color visual cannot display colors correctly in the True colorvideo device. Mostly, CAD applications such as Cadence, Mentor and CATIA have this problem.Youcan configure 256-color emulation to fix this problem. In the Xconfig,change Default Visual and Backing Store options as following: DefaultVisual: PseudoColorBacking Store: When MappedThese options will enable 256-color emulation feature in Xmanager.14. Gnome terminal fails to open in RedHat 7.3.The problem occurs due to the font used by gnome-terminal.To fix this problem, configure xfs program and add the specific font server into the font list ofXconfig.Comment the following line out in the file /etc/X11/fs/config.#no-listen = tcpRestart xfs process or reboot the system.Open Xconfig utility.Choose Font tab.Click Add Font Server button.In the Host box, enter the hostname or IP address of Linux.In the Port box, enter 7100.Restart Xmanager.Make sure that the font server should be listed in the bottom of the font list.15. Does Xmanager support Windows or Citrix terminal server?Xmanager supports both Windows terminal server and Citrix MetaFrame server. To use Xmanager in thoseenvironment, please follow the guidelines below:For XDMCP connectionInstall Xmanager into the Windows or Citrix terminal server.Run Xbrowser in each terminal client. Xbrowser is installed with Xmanager.For Xstart sessionCheck Allocate display number automatically on in the Xstart Advanced Options dialog box.16. Now that I have purchased Xmanager, do I need to download any install file? And how can I applymy product keyXmanager evaluation is fully functional copy and there is no need to reinstall additional software.To apply your product key follow the steps below:Open Xbrowser.From the Help menu and click About Xbrowser.Click Enter Product Key.RESULT: Registration window opens up.Enter your product key and click OK.Also, expiration date notice window will not appear again once you apply your product key.可参考/products/xmg_faq.html#pl。
工控远程操作方法

工控远程操作方法
工控远程操作是指通过远程方式对工业控制系统进行操作和管理。
以下是一些常用的工控远程操作方法:
1. VPN(Virtual Private Network,虚拟私人网络):在工控系统和操作人员之间建立一个安全的网络连接,通过VPN可以实现远程访问和操作工控系统。
2. 远程桌面:使用远程桌面软件,比如Windows的远程桌面功能、TeamViewer 等,通过远程连接到工控系统所在的计算机,然后在本地进行操作。
3. 安全终端服务器:安全终端服务器通过终端服务器和工控设备之间的连接,使远程运维人员可以通过网络连接到工控设备进行操作和管理。
4. 远程控制软件:使用专门的远程控制软件,如VNC、AnyDesk等,在远程计算机上实时查看和操作工控系统。
5. 无线网络:使用无线网络连接到工控系统,可以通过手机、平板电脑等移动设备进行远程操作,方便在现场外对工控系统进行管理。
无论采取何种远程操作方法,都需要注意确保网络安全,避免未经授权的访问和操作,保护工控系统的安全和稳定运行。
远程控制实验报告

远程控制实验报告引言:远程控制是一种通过无线或有线网络将控制信号传输到远程设备的技术。
它已广泛应用于各个领域,如自动化系统、机器人技术、航空航天领域等。
本实验旨在探索远程控制技术的原理和应用,并通过实践操作,验证其可行性和效果。
一、实验背景远程控制实验是现代通信技术的重要应用之一。
随着科技的不断发展,远程控制在各个领域的应用越来越广泛。
例如,随着物联网技术的兴起,人们可以通过手机APP远程控制家居设备,如灯光、空调等。
此外,在工业自动化中,远程控制也是实现生产流程优化和降低人力成本的重要手段。
因此,了解远程控制技术的原理和方法,对我们掌握现代科技的应用具有重要意义。
二、实验目的本实验旨在通过构建一个简单的远程控制系统,探究远程控制技术的原理和应用。
具体目标包括:1. 理解远程控制的基本原理;2. 学习使用无线或有线网络进行数据传输;3. 验证远程控制系统的可行性和效果;4. 探索远程控制在实际应用中的局限性和改进空间。
三、实验步骤与方法1. 硬件构建首先,我们需要准备一台控制主机(如计算机)和一个被控设备(如灯光或电机)。
将控制主机和被控设备连接到同一个局域网中,确保网络连接正常。
如果使用无线网络,请确保无线信号稳定。
2. 软件设置在控制主机上安装远程控制软件,并进行相应的设置。
设置包括网络连接参数、设备识别码等。
根据软件的提示进行操作,并确保设置正确。
3. 远程控制打开远程控制软件,在主界面上选择要控制的设备,并进行相应的操作。
观察被控设备的状态,验证远程控制的效果。
可以尝试开关灯光、调节电机转速等操作。
4. 分析与总结根据实际操作结果,分析远程控制系统的可行性和效果。
总结实验中遇到的问题和改进的空间,并展望远程控制技术的未来发展方向。
四、实验结果与讨论通过实际操作,我们成功地搭建了一个远程控制系统,并验证了其可行性和效果。
通过远程控制软件,我们可以在主机上实时控制被控设备的状态。
例如,我们可以通过软件远程开启或关闭灯光,调节电机的转速等。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
四 川 大 学 计 算 机 学 院、软 件 学 院 实 验 报 告
课程名称 信息安全产品开发实践 实验课时 5
实验项目 远程控制系统 实验时间 2011年9月22号
实验目的
1) 继续了解Linux下C语言程序开发的过程 2) 继续了解Socket网络编程 3) 回顾流套接字与数据报套接字 4) 了解远程控制系统的流程及其实现的两种方式(TCP和UDP)
实验环境 VMware5.0,RedHat Linux 9.0
实验内容(算法、程序、步骤和方法)
• 利用数据报套接字实现一个简单的远程控制系统: 1.客户端输入“quit”,客户端程序与服务器端程序打印退出信息,终止程序的执行;
2.客户输入命令,客户端将命令通过流套接字发送给客户端,服务器执行收到的命令,并将结果发送到客户端显示;
3.如果没有客户输入的命令,服务器发送命令非法信息,并在客户端显示该条信息。
4.编写实验报告: 列出程序运行状态、截图、配文字说明; 在进行试验之前先来回顾一下UDP套接字编程的流程:
上图反应了在进行数据报套接字编程时服务器端和客户端需要做得工作,从中我们可以看出服务器端需要经过五个步骤,而客户端只需要四个步骤。
远程控制的原理如下: • 客户端接收用户输入的命令,客户端通过套接字将命令传送给服务器端, • 服务器在收到用户的命令,对命令进行解析 • 在服务器端调用对应的命令 • 并将命令执行的结果发送给客户端,从而实现远距离控制的功能。
从远程控制的原理并结合UDP套接字编程的流程我们可以画出用UDP实现远程控制的流程图,如下: 下面介绍本试验的具体步骤: (1):打开虚拟机,在Linux下的VI编辑器中编写服务器端程序UDPserver.c (2)使用命令gcc –o UDPserver UDPserver.c –g编译; (接上) 实验内容(算法、程序、步骤和方法)
(3):编写客户端程序:UDPclient.c (4): 使用gcc –o UDPclient UDPclient.c –g命令编译 (5)使用setup命令配置虚拟机的IP地址为10.0.0.222 (6):执行服务器端代码(./UDPserver),客户端连接服务器(./UDPclient 10.0.0.22): (6):客户端输入字符串ls,服务器端解析输出结果: (7):客户端继续输入字符串who,how,服务器端解析输出结果 (8):客户端输入quit命令,断开连接,服务器正确反应,与客户端脱离连接 附试验源代码:
UDPserver.c #include #include #include #include #include #include
#define PORT 8900 #define BUFSIZE 2048 int execute(char*command,char*buf) { FILE *fp; int count; char commandbuf[2056];
if ((NULL==command)||(NULL==buf)) { perror("command or buf is empty\n"); return -1; } count =0; memset(commandbuf,0,2056); strcat(commandbuf,"sh -c "); strcat(commandbuf,command); fprintf(stderr,"the command is %s\n",commandbuf);
if (NULL==(fp=popen(commandbuf,"r"))) { perror("create pipe error\n"); return -1; } while ((count<2047) && (EOF!=(buf[count++]=fgetc(fp)))); buf[count-1]='\0'; return count; }
int main() { int sockfd; int conn_sock; char sendbuf[BUFSIZE]; char recvbuf[BUFSIZE]; int sendnum; int recvnum; int length; struct sockaddr_in client; struct sockaddr_in server; int opt; int cnt; int lens;
memset(&client,0,sizeof(client)); memset(&server,0,sizeof(server)); memset(sendbuf,0,BUFSIZE); memset(recvbuf,0,BUFSIZE); length=0; sockfd=-1; conn_sock=-1; opt=SO_REUSEADDR;
if(-1==(sockfd=socket(AF_INET,SOCK_DGRAM,0))) { perror("Create socket error\n"); exit(1); } setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
server.sin_family=AF_INET; server.sin_addr.s_addr=htonl(INADDR_ANY); server.sin_port=htons(PORT); if (-1==bind(sockfd,(struct sockaddr*)&server,sizeof(struct sockaddr)))
{ perror("bind socket error\n"); close(sockfd); return -1;
} while(1) { while(1) {
memset(recvbuf,0,BUFSIZE); memset(sendbuf,0,BUFSIZE); length=sizeof(struct sockaddr); if (0>=(recvnum=recvfrom(sockfd,recvbuf,BUFSIZE,0,(struct sockaddr*)&client,&length)))
{ perror("the commucation error\n"); close(sockfd); return -1; } recvbuf[recvnum]='\0';
fprintf(stderr,"the command is:%s\n",recvbuf); if (0==strcmp(recvbuf,"quit")) { fprintf(stderr,"the client is quit\n"); break; }
if (1>=(cnt=execute(recvbuf,sendbuf))) { sprintf(sendbuf,"the invalid command,please try again\n");
} fprintf(stderr,"the result is \n%s",sendbuf); sendnum=strlen(sendbuf); lens=sizeof(struct sockaddr); if (0>=sendto(sockfd,sendbuf,sendnum,0,(struct sockaddr*)&client,lens))
{ perror("the commucation error\n"); close(sockfd); return -1;
} } } close(sockfd); } UDPclient.c #include #include #include #include #include #include #include
#define PORT 8900 #define BUFSIZE 2048
void printusage(char*command) { if (NULL==command) exit(-1);
fprintf(stderr,"the useage of %s :",command); fprintf(stderr,"%s IPADDR\n",command); return; }
int main(int argc,char** argv) { int sockfd; int length;