. .
-优选
嵌入式实验报告
题目:linux串口和网络编程
一、实验目的:
1、强化本学期所学的相关的容。
2、掌握串口相关设置。
3、强化基于TCP网络传输的三次握手。
4、自学Linux线程的使用。
二、实验容:
本试验基于server和client的透明传输来实现类似于QQ的聊天功能。
三、实验过程:
1、linux开发环境的建立
2、嵌入式linux系统的搭建
1>BootLoader的移植
2>linux系统的裁剪与移植
Linux核裁剪
./make_image生成自己的uImage2638
上电验证:
3>根文件系统的移植
修改hostname为:whmtt
./mkcramfsdisk_new
大小从教师给的40000到37b00〔因为有的没有用到,大小变小了〕:
. .
-优选
上电验证:
3、
相关代码:
#include <>
#include <sys/>
#include <>
#include <sys/>
#include <netinet/>
#include <>
#include <>
#include <>
#define SERVER_PORT 20000 //设置效劳端口
#define CLIENT_PORT ((20001+rand())%65536) //设置客户端端口〔随机〕
#define BUFFER_SIZE 256
#define LENGTH_OF_LISTEN_QUEUE 10 //可窃听队列长为10
#define WELE_MESSAGE "wele to connect the server."
void usage(char* name)
{
printf( "usage: %s IpAddr\n " ,name);
}
struct sockaddr_in servaddr,cliaddr;
int servfd,clifd,length=0;
. .
-优选
struct sockaddr_in servaddr,cliaddr;
socklen_t socklen=sizeof(servaddr);
char buf[BUFFER_SIZE],buf2[BUFFER_SIZE];
pthread_t tidp,tidp2;
int pth;
int runflag=0;
void *Thread1(void *arg) /*等待runflag为1,当为1时清空buf,
同时接收来自server的数据并输出。
但当没有清空,那么break.*/
{
while(runflag){
memset(buf,0,BUFFER_SIZE);
length=recv(clifd,buf,BUFFER_SIZE,0);
if(strstr(buf,"$")>0){runflag=0;printf("stop!\n");break;}
if(length>0) printf("from server:%s",buf);
}
}
void *Thread2(void *arg) /*等待发送数据给Server*/
{
printf("Please input your words to Server:--$ to stop\n");
while(runflag){
memset(buf2,0,BUFFER_SIZE);
.
嵌入式串口和网络编程实验报告 来自淘豆网m.daumloan.com转载请标明出处.