46 {
47 rt_kprintf(“socket bind failed.
”);
48 closesocket(sockfd);
49 return -RT_ERROR;
50 }
51 rt_kprintf(“socket bind network interface device(%s) success!
”, netdev-》name);
52
53 /* 初始化预连接的服务端地址 */
54 server_addr.sin_family = AF;
55 server_addr.sin_port = htons(SERVER_PORT);
56 server_addr.sin_addr.s_addr = inet_addr(SERVER_HOST);
57 rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
58
59 /* 连接到服务端 */
60 if (connect(sockfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) 《 0)
61 {
62 rt_kprintf(“socket connect failed!
”);
63 closesocket(sockfd);
64 return -RT_ERROR;
65 }
66 else
67 {
68 rt_kprintf(“socket connect success!
”);
69 }
70 write(sockfd,send_buf,sizeof(send_buf));
71 read(sockfd,read_buf,sizeof(read_buf));
72 rt_kprintf(“%s
”,read_buf);
73 /* 关闭连接 */
74 closesocket(sockfd);
75 return RT_EOK;
76}
77MSH_CMD_EXPORT(bing_test, bind network interface device test);
责任编辑:pj
关于模拟技术就介绍完了,您有什么想法可以联系小编。