学习Vxworks之前希望读者已经具备计算机网络、操作系统、C/C++、网络通信等基础知识。建议阅读CSAPP,打好基础。 Vxworks为美国风河公司推出的高性能实时操作系统,现已广泛应用于各类大型项目,同时Tplink等公司也应用Vxworks作为某些路由器的操作系统。 实时性在计算机中分为强实时、软实时,vx所支持的为强实时,Linux普遍为软实时。 在一个实时操作系统之中,最关注的是每个任务在多长时间内可以完成。简单地说,实时和分时操作系统最大的不同在于 **时限(deadline)**这个概念。它不允许任何超出时限的错误。超时错误会带来损害甚至导致系统失败、或者导致系统不能实现它的预期目标。软实时系统的时限是一个柔性灵活的,它可以容忍偶然的超时错误。失败造成的后果并不严重,例如在网络中仅仅是轻微地降低了系统的吞吐量。
现代实时系统是在多任务和任务间通信的基础上建立起来的。一个多任务的环境允许将实时应用构造成一组独立的任务,每个任务拥有各自的线程和一套系统资源。为了协调任务间的行为,任务间的通信设备允许这些任务通过同步和通信操作协调各自的活动。在VxWorks 操作系统中,任务间通信设备包括信号量、消息队列、管道以及网络套接字等设备。 在实时系统中,处理中断是另一个主要功能,这是因为中断是将外部事件通知系统的重要方式。为了能得到较快的中断响应,VxWorks操作系统里中断服务程序(ISR)在一个专门的上下文中执行,是处于任务的上下文之外。 Vxworks实时内核Wind提供了基本的多任务环境,并提供了相应的调度算法。每个任务均具备自己的上下文,上下文均保存在任务控制块TCB中。其中TCB包括以下内容:
事先请参阅Wind River Network Stack for VxWorks 6 Programmer's Guide, 6.6的文档!里面的文档说的很详细!
The parameters used to configure the FTP server in Workbench are described in Table 2-9. Authentication callback routine FTPS_AUTH_CALLBACK_HOOK You can use your own routine to authenticate clients. To do this, specify a function pointer for the FTPS_AUTH_CALLBACK_HOOK. The FTP server will call this routine to authenticate clients.
The prototype for this routine is as follows:
int myAuthenticateCallback (Ipftps_session * session, char * password);
It should return 0 (zero) if the password is valid for the session, or 1 (one) if you cannot validate the password. If you do not specify an authentication routine, the server will call its own default authentication callback routine that allows read-only access to the user anonymous with no password.
If you set a function pointer here, you must also set the FTPS_INSTALL_CALLBACK_HOOK to TRUE in order to install this callback hook.
FTPS_INSTALL_CALLBACK_HOOK FALSE
Indicates whether the FTP server uses the authentication callback routine that you specified by the configuration parameter FTPS_AUTH_CALLBACK_HOOK to authenticate clients.
If this is FALSE, the server instead uses its own authentication routine—one that allows the user anonymous with no password.
修改后就是如下面显示:
Telnet 协议是 TCP/IP 协议族中应用最广泛的协议。
它允许用户(Telnet 客户端)通过一个协商过程来与一个远程设备进行通信。
Telnet 协议是基于网络虚拟终端 NVT(Network Virtual Termina1)的实现,NVT 是虚拟设备,连接双方(客户机和服务器)都必须把它们的物理终端和 NVT 进行相互转换。
只要客户机或服务器要发送命令序列而不是数据流,它就在数据流中插入一个特殊的保留字符,该保留字符叫做“解释为命令”(IAC ,Interpret As Command) 字符。当接收方在一个入数据流中发现 IAC 字符时,它就把后继的字节处理为一个命令序列。
双方在进行Telnet连接时,要进行选项协商。
比如:使用字符方式、窗口的大小,终端的类型都要进行协商。而协商是通过TELNET所支持的命令来实现的。
协商完成,telnet server才返回登录信息,否则无法登录。
本文协商过程通过程序的一个函数实现自动化。
下载地址
VxWorks 6.9 配置多网口
#include "vxWorks.h"
#include "sockLib.h"
#include "inetLib.h"
#include "stdioLib.h"
#include "strLib.h"
#include "hostLib.h"
#include "ioLib.h"
//#include "tcpExample.h"
#define SERVER_PORT_NUM 5001
#define SERVER_WORK_PRIORITY 100
#define SERVER_STACT_SIZE 10000
#define SERVER_MAX_CONNECTIONS 4
#define REQUEST_MSG_SIZE 1024
#define REPLY_MSG_SIZE 500
#define ERROR (-1)
int tcp_server(void)
{
struct sockaddr_in serverAddr;
struct sockaddr_in clientAddr;
char rcvBuf[REQUEST_MSG_SIZE];
int sockAddrSize;
int sFd;
int newFd;
int nByte;
//1 create socket
if((sFd = socket(AF_INET, SOCK_STREAM, 0)) == ERROR)
{
printf("create socket error!\n");
return ERROR;
}
//2 init some parameter
sockAddrSize=sizeof(struct sockaddr_in);
bzero((char *)&serverAddr, sockAddrSize);
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(SERVER_PORT_NUM);
serverAddr.sin_addr.s_addr=htonl(INADDR_ANY);
serverAddr.sin_len=(unsigned char)sockAddrSize;
//3 bind socket
if(bind(sFd,(struct sockaddr*)(&serverAddr),sockAddrSize)== ERROR)
{
printf("bind error!\n");
close(sFd);
return ERROR;
}
//3 listen client
if(listen(sFd,SERVER_MAX_CONNECTIONS) == ERROR)
{
printf("listen error!\n");
close(sFd);
return ERROR;
}
//下面可以使用死循环或线程创建accept,并创建相对应的接收线程
//4.accept server
newFd = accept(sFd,(struct sockaddr*)(&clientAddr),&sockAddrSize);
printf("server get connection from %s\n",inet_ntoa(clientAddr.sin_addr));
while(1)
{
//5.receive
nByte = recv(newFd, rcvBuf, REQUEST_MSG_SIZE, 0);//收不到数据阻塞
rcvBuf[nByte] = '\0';
printf("server received datas : %s\n", rcvBuf);
if(rcvBuf[0]=='q')
break;
}
//6.close *Fd
close(newFd);
close(sFd);
return 0;
}
int tcp_client(char * serverName)
{
struct sockaddr_in serverAddr;
char sendBuf[REQUEST_MSG_SIZE];
int sockAddrSize;
int sFd;
//1 create socket
if((sFd = socket(AF_INET, SOCK_STREAM, 0)) == ERROR)
{
printf("create socket error!\n");
return ERROR;
}
//2 init some parameter
sockAddrSize=sizeof(struct sockaddr_in);
bzero((char *)&serverAddr, sockAddrSize);
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(SERVER_PORT_NUM);
serverAddr.sin_len=(unsigned char)sockAddrSize;
if((serverAddr.sin_addr.s_addr = inet_addr(serverName))== ERROR &&
(serverAddr.sin_addr.s_addr = hostGetByName(serverName)) == ERROR)
{
printf("unknown serverName\n");
close(sFd);
return ERROR;
}
//3 connnect server
if(connect(sFd,(struct sockaddr*)(&serverAddr),sockAddrSize) == ERROR)
{
printf("connect error\n");
return ERROR;
}
//4:send datas to server
printf("please input chars:\n");
//send(sFd,sendBuf, strlen(sendBuf), 0);
while(1){
fgets(sendBuf,REQUEST_MSG_SIZE,stdin);
write(sFd,sendBuf, strlen(sendBuf));
if(sendBuf[0] == 'q')
break;
}
//5 close sFd
close(sFd);
return 0;
}
© 2023 VxWorks Club