Download presentation
Presentation is loading. Please wait.
Published byGilbert Pitts Modified over 9 years ago
1
U niversity of S cience and T echnology of C hina VxWorks 及其应用开发 陈香兰 xlanchen@ustc.edu.cn http://staff.ustc.edu.cn/~xlanchen 2006 年 7 月
2
U niversity of S cience and T echnology of C hina 2 课程内容 VxWorks 和 Tornado 简介 任务和任务间通信 信号、中断处理与定时机制 调试环境与实例分析 网络编程 VxWorks 操作系统配置
3
U niversity of S cience and T echnology of C hina VxWorks 网络编程 xlanchen@2006.7.26
4
U niversity of S cience and T echnology of C hina 4 Socket 编程接口
5
U niversity of S cience and T echnology of C hina 5 Client/server 编程模式 网络编程的主要模式是 client/server Client :请求服务的一方 Server :提供某种服务的一方 例如 WWW 、 telnet Client 与 Server 的划分不是绝对的
6
U niversity of S cience and T echnology of C hina 6 在 TCP/IP 协议中, Client/Server 之间可以 使用传输层协议( TCP 、 UDP )进行通信 Client 端通常通过指定服务器的 IP 地址和 端口号来找到服务端 也可以通过广播的方式(很少使用)
7
U niversity of S cience and T echnology of C hina 7 服务端程序设计的两种基本模式 不管使用 TCP 还是 UDP 协议,在程序结构 上都可以使用两种基本模式: 循环模式 并发模式 循环模式:服务端进程一次只能处理一个 请求,为单进程结构 并发模式:服务端进程一次可以处理多个 请求,通常使用多进程结构
8
U niversity of S cience and T echnology of C hina 8 面向连接服务端( TCP )的循环模式 socket bind listen while(accept) { While : send/recv close }
9
U niversity of S cience and T echnology of C hina 9 面向连接服务端( TCP )的并发模式 socket bind listen while(accept) { taskSpawn } Task : while : send/recv close
10
U niversity of S cience and T echnology of C hina 10 我们通过实例讲解 VxWorks 下 TCP/IP 网 络编程 tcpExample.h tcpClient.c tcpServer.c
11
U niversity of S cience and T echnology of C hina 11 tcpExample.h
12
U niversity of S cience and T echnology of C hina 12 tcpClient.c
13
U niversity of S cience and T echnology of C hina 13
14
U niversity of S cience and T echnology of C hina 14 网络字节序 不同体系结构的 CPU 使用不同的字节序 Big_endian , little_endian 网络上规定使用 big_endian 下列宏用于进行主机字节序与网络字节序 之间的转换 htonl— host to net long htons— host to net short ntohl— net to host long ntohs— net to host short
15
U niversity of S cience and T echnology of C hina 15 VxWorks 提供操作以太网地址的函数
16
U niversity of S cience and T echnology of C hina 16
17
U niversity of S cience and T echnology of C hina 17
18
U niversity of S cience and T echnology of C hina 18 tcpServer.c
19
U niversity of S cience and T echnology of C hina 19
20
U niversity of S cience and T echnology of C hina 20
21
U niversity of S cience and T echnology of C hina 21
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.