|
最近我使用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);
}
} |
|