When you create the socket, try using IPPROTO_TCP instead of 0 as the protocol 
for both the client and server. I believe this should solve your problem.

Regards,
Anand Balagopalakrishnan
Texas Instruments Inc
India

________________________________
From: [email protected] 
[mailto:[email protected]] On Behalf Of 
[email protected]
Sent: Friday, April 03, 2009 11:43 AM
To: [email protected]
Subject: help: how to config kernel to support tcp udp AF_INET


Hi;

   Can anyone tell me how to configure kernel to support AF_INET.

   Now  i work with Monavista 2.6.10 on dm6446 evm.

    When i run the server on the testboard

     the server print

      bind start
      bind end
      listen start
      listen end
      server waiting
      accept start



    When i run the client on the testboard,

     the client print

      connect start

    the client can not connect on the server

But when i run the the same test code on the pc

the server print

bind start
bind end
listen start
listen end
server waiting
accept start



the client print

connect start
accept end
read start
connect end
write start
read end
write start
write end
server waiting
accept start
write end
read start
read end
char from server = B

    The client can connect the server .



Here is the  server code

#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<sys/un.h>
#include<unistd.h>

#include<netinet/in.h>
#include<arpa/inet.h>

int main()
{
 int server_sockfd, client_sockfd;
 int server_len, client_len;

// struct sockaddr_un server_address;
// struct sockaddr_un client_address;

 struct sockaddr_in server_address;
 struct sockaddr_in client_address;


 unlink("server_socket");
// server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
 server_sockfd = socket(AF_INET, SOCK_STREAM, 0);

// server_address.sun_family = AF_UNIX;
// strcpy(server_address.sun_path, "server_socket");

 server_address.sin_family = AF_INET;
// server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
// server_address.sin_port = 9734;
 server_address.sin_addr.s_addr = htonl(INADDR_ANY);
 server_address.sin_port = htons(9734);
 server_len = sizeof(server_address);

 printf("bind start\n");
 bind(server_sockfd, (struct sockaddr *)&server_address, server_len);
 printf("bind end\n");

 printf("listen start\n");
 listen(server_sockfd, 5);
 printf("listen end\n");

 while(1)
 {
  char ch;

  printf("server waiting\n");

  client_len = sizeof(client_address);
  printf("accept start\n");
  client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, 
&client_len);
  printf("accept end\n");

  printf("read start\n");
  read(client_sockfd, &ch, 1);
  printf("read end\n");

  ch++;
  printf("write start\n");
  write(client_sockfd, &ch, 1);
  printf("write end\n");

  close(client_sockfd);

 }
}

Here is the client code



#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<sys/un.h>
#include<unistd.h>

#include<netinet/in.h>
#include<arpa/inet.h>

int main()
{
 int sockfd;
 int len;
// struct sockaddr_un address;
 struct sockaddr_in address;

 int result;
 char ch= 'A';

// sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
 sockfd = socket(AF_INET, SOCK_STREAM, 0);

// address.sun_family = AF_UNIX;
// strcpy(address.sun_path, "server_socket");

 address.sin_family = AF_INET;
 address.sin_addr.s_addr = inet_addr("127.0.0.1");
// address.sin_port = 9734;
 address.sin_port = htons(9734);
 len = sizeof(address);

 printf("connect start\n");
 result = connect(sockfd, (struct sockaddr *)&address, len);
 printf("connect end\n");

 if(result == -1)
 {
  perror("oops: client1");
  exit(1);

 }

 printf("write start\n");
 write(sockfd, &ch, 1);
 printf("write end\n");

 printf("read start\n");
 read(sockfd, &ch, 1);
 printf("read end\n");

 printf("char from server = %c\n", ch);

 close(sockfd);

 exit(0);
}

Thanks.
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to