This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

TCP/IP problem


Dear Sir,


We have written a small TCP client program which connects to a TCP server on
Port 7734 .The hardware platform is EDB7212 . The Error message in connect
system call is "Message Too long".The Progam that we tried is :


#include <network.h>
#include <cyg/kernel/kapi.h>
#include <stdio.h>
#include <string.h>


#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
static char stack[2][STACK_SIZE];
static cyg_thread thread1,thread2;
static cyg_handle_t t1,t2;
struct sockaddr_in local,cli;

int ser;

void server(struct bootp *bp)
{
	int c,i,*l,n,pp;
	char chdata='*';

	if((ser=socket(AF_INET,SOCK_STREAM,0))<0)
	{
		perror("\nSERVER  :  socket");
		exit(1);
	}
	printf("\nSERVER Socket Created");
	cyg_thread_delay(50);

    memset(&local, 0, sizeof(local));

	local.sin_family=AF_INET;
	local.sin_port=ntohs(7734);
	local.sin_addr.s_addr=INADDR_ANY;


	cli.sin_family=AF_INET;
	cli.sin_port=htons(7734);
	cli.sin_addr.s_addr=INADDR_ANY;

	diag_printf("Trying to bind...");

	if(bind(ser,(struct sockaddr *) &local,sizeof(local))<0)
	{
		perror("\nSERVER  :  bind");
		exit(1);
	}
	diag_printf("done\n");
	diag_printf("Trying to listen...");
	listen(ser,5);
	diag_printf("done\n");


	while(1)
	{
		diag_printf("\nBefore accept...");
		pp=sizeof(cli);
		c=accept(ser, (struct sockaddr *)&cli,&pp);
		if(c==-1)
		{
			perror("\nSERVER  :  accept");
			exit(1);
		}
		diag_printf("done. \n Accept Sucessful");

		diag_printf("Trying to read from the server...");

		if(n=read(c,&chdata,1)<0)
		{
			perror("\nSERVER  :  read failed!!!");
			exit(1);
		}

		diag_printf("\nCLIENT SENT   %c",chdata);

		/***********************/
		chdata = '@';
				diag_printf("Trying to send @...");

			 	if(write(c,&chdata,1)<0)
			 	{
					perror("\nSERVER  :  write failed");
					exit(1);
				}

				diag_printf("done\nSERVER WROTE TO CLIENT");
		close(c);
		/***********************/


	}
	close(ser);
}


void client(struct bootp *bp)
{

	int c;
	int i,s,l;
	char chd = '$';
	struct sockaddr_in toCon;

	s=socket(AF_INET,SOCK_STREAM,0);

	if(s<0)
	{
		perror("\nCLIENT  :  socket");
		exit(1);
	}
	printf("\nClinet Socket created");
	cyg_thread_delay(50);



    toCon.sin_family=AF_INET;
    toCon.sin_addr = bp->bp_yiaddr;
    toCon.sin_port=htons(7734);




	l=sizeof(toCon);

	diag_printf("Trying to connect to the server...");

	c=connect(s,(struct sockaddr*) &toCon,sizeof(toCon));


	if(c<0)
	{
		perror("\nCLIENT  :  connect");
		diag_printf("The Error number: %d", errno);
		exit(1);
	}
	diag_printf("done.");

	diag_printf("Trying to write a char to the server...");

	    l=sizeof(local);
		if(write(c,&chd,1)<0)
		{
			perror("\nSERVER  :  write failed");
			exit(1);
		}

		diag_printf("done\nWROTE TO SERVER");
		diag_printf("Trying to read a byte from the server...");

	if(read(c,&i,1)<0)
	{
		perror("\nSERVER  :  read failed");
		exit(1);
	}

	diag_printf("done\nSERVER WROTE  : %d",i);
	diag_printf("\nCLIENT SAYS BYE");
	close(c);
}

void
net_test(cyg_addrword_t param)
{


    if (eth0_up) {
        server(&eth0_bootp_data);
    }
 }
void
net_test1(cyg_addrword_t param)
{


    if (eth0_up) {
        client(&eth0_bootp_data);
        }
 }
void cyg_start(void)
{
	init_all_network_interfaces();

	cyg_thread_create(4,net_test,0,"Server",&stack[0],STACK_SIZE,&t1,&thread1);

cyg_thread_create(5,net_test1,0,"Client",&stack[1],STACK_SIZE,&t2,&thread2);

	cyg_thread_resume(t1);
	cyg_thread_resume(t2);

	cyg_scheduler_start();

}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]