天嵌 ARM开发社区

 找回密码
 注册
查看: 1576|回复: 1

tcp客户端问题

[复制链接]
lzw_happy 发表于 2010-11-10 13:59:10 | 显示全部楼层 |阅读模式
最近我使用TQ2440开发板的网络功能,做为客户端和PC机上的服务器端相连,开发板接在局域网的交换机上,共两台,但是发现两块开发板不能同时和PC机上的服务器相连,连一台稳定,请问是什么原因啊,代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>


char *host_name="192.168.1.120";
int port=3333;

struct student
{
char name[20];
char num[20];
float score;
}t={"xiejian","200701415",89.9};

int main ( )
{

         char buf[502];
         int socket_descriptor;
         struct sockaddr_in pin;
         bzero(&pin,sizeof(pin));
         pin.sin_family=AF_INET;
         inet_pton(AF_INET,host_name,&pin.sin_addr);
         pin.sin_port=htons(port);
         if((socket_descriptor=socket(AF_INET,SOCK_STREAM,0))==-1)
         {
          perror("Error openung socket!\n");
          exit(1);
         }
         if(connect(socket_descriptor,(void *)&pin,sizeof (pin))==-1)
         {
          perror("can not connecting to server!\n");
          exit (1);
         }
         printf("Send message  to server ...\n");
         
         memset(buf,0,502);
         while(1)
   {
             if(recv(socket_descriptor,buf,sizeof(buf),0)==-1)
     {
      perror("can not receive response !\n");
      exit (1);
     }
     else
     {
                     printf("receive is %x %x %x %x %x %x %x \n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6]);
     }
       sleep(1);
   }         
}
天嵌_support1 发表于 2010-11-11 12:12:29 | 显示全部楼层
1# lzw_happy


有没有IP冲突呀。或者Mac地址冲突
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-10-5 18:28 , Processed in 1.027383 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表