delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/06/26/08:40:19

X-Spam-Check-By: sourceware.org
X-Virus-Scanner: This message was checked by NOD32 Antivirus system for Linux Server. For more information on NOD32 Antivirus System, please, visit our website: http://www.nod32.com/.
Message-ID: <39522.212.201.104.13.1151325602.squirrel@webmail.iitk.ac.in>
In-Reply-To: <20060626122250.GG11077@calimero.vinschen.de>
References: <35711 DOT 212 DOT 201 DOT 104 DOT 13 DOT 1151323919 DOT squirrel AT webmail DOT iitk DOT ac DOT in> <20060626122250 DOT GG11077 AT calimero DOT vinschen DOT de>
Date: Mon, 26 Jun 2006 18:10:02 +0530 (IST)
Subject: Re: problem running a UDP client and server
From: "Varun Sharma" <varunsh AT iitk DOT ac DOT in>
To: cygwin AT cygwin DOT com
Reply-To: varunsh AT iitk DOT ac DOT in
User-Agent: SquirrelMail/1.4.5-1
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hi,
 Thanks a lot for your help, but my flag option is a default 0. This is
the same option that I am using with a normal UDP client and normal UDP
server which are working fine. Should I change this. I am attaching the
piece of code of the client:


in_addr_t gethostaddr(name)
     char *name;
{
   in_addr_t addr;
   register struct      hostent *hp;

   if ((addr = (in_addr_t)inet_addr (name)) != -1)
      return (addr);

   hp = (struct hostent*) gethostbyname(name);
   if (hp != 0)
      return (*(in_addr_t *)hp->h_addr);
   else
      return (0);
}
/********************************************************/

int Do_Client_Work(char * serverName, unsigned short int serverPort, int
rpt_cnt)
{
    int i,pid,pc,sock,rcnt;
    struct sockaddr_in dst;     /* Echo server address */
    struct sockaddr_in src;     /* Source address of echo */
    struct in_addr dst_addr;
    unsigned short echoServPort;     /* Echo server port */
    int fromSize;           /* In-out of address size for recvfrom() */
    char *servIP;                    /* IP address of server */
    int incnt,outcnt,xcnt;               /* Length of received response */
    struct hostent *hp;

/********************************************************/
   struct timeval *tp;

   struct ABWreport *ptrep;

   struct ABWrec *srec,*rrec;
   double sleeptime = DELAYTIME,ms1,djn,ms_iter;
   int  nc,nt,np,ppseq,rnum,endcnt=0,okfl=0;
   int  npkt = NPKT;
   int  pktsend;
   int  write_error = NO;
   int  dcnt = 0;
   double tpole[100];
   char *ptext, rdata[MAXMESG],sdata[MAXMESG];
/********************************************************/
   double sumt,sumf,sumr,avt_abw,avr_rtt,avf_abw,
	si_t_abw, si_f_abw,si_rtt,di_t_abw, di_f_abw,di_rtt,
        arr_t_abw[NMODMAX],arr_f_abw[NMODMAX],arr_rtt[NMODMAX];
/********************************************************/
   int timeout = 500000;

tp = (struct timeval *)(malloc (sizeof (struct timeval)));
sleeptime=50;
srec = (struct ABWrec *) sdata;
rrec = (struct ABWrec *) rdata;
bzero((char *) srec, sizeof (struct ABWrec));
ptext=sdata+124;
strcpy(ptext,klic);
srec->rnum = htonl ((u_long) 2);

pktsend=1;
npackets=ntrains*npkt;
xcnt=1;

printf("The server name is %s and the port is %d\n",serverName, serverPort);
/* DNS resolution */
dst_addr.s_addr = gethostaddr(serverName);
printf("The address is %d\n",dst_addr.s_addr);
/*
	char *dummy = (char *) malloc(9);
	strcpy(dummy,"127.0.0.1");
	hp = gethostbyname(dummy);
if (hp == 0) perror("Unknown host");
*/
if (dst_addr.s_addr ==0) {
	fprintf (stderr,"Destination: %s: uknown host\n",serverName);
	exit (1);
}

/* Create a datagram/UDP socket */
    if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
        DieWithError("socket() failed");

	//fcntl(sock, F_SETFL, O_NONBLOCK);

	//setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(char *) &timeout,sizeof(timeout));
/* Construct the server address structure */
    memset(&dst, 0, sizeof(dst));    /* Zero out structure */
//    dst.sin_addr.s_addr = inet_addr(servIP);  /* Server IP address */
//    dst.sin_addr.s_addr = gethostaddr(servIP);  /* Server name */
    dst.sin_family = AF_INET;                 /* Internet addr family */
    dst.sin_addr = dst_addr;  /* Server addr */
//	bcopy((char *)hp->h_addr, (char *)&dst.sin_addr,hp->h_length);
    dst.sin_port   = htons(serverPort);     /* Server port */

if ((pid=fork()) == 0) {
/*********  child = sender ************************/
//        printf("I am child and I will do all sendings: %d,%d to %s
\n",ntrains,npkt,serverName);

if (connect (sock, (struct sockaddr *) &dst, sizeof (dst)) < 0) {
      perror ("fabws: connect");
	exit(-1);
}

printf("The values of socket is sock %d\n",sock);

signal(SIGALRM,time_out);


for (i=0;i<rpt_cnt;i++) {
   for (nt = 1; nt <= ntrains; nt++) {
                srec->ppseq = htonl ((u_long) nt);
        for (nc = 1; nc <= npkt; nc++) {
    sprintf(ptext,"Tu je NC,NT=%d,%d a msg=%s",nc,nt,klic);       /*
Second arg: string to echo */
                srec->num = htonl ((u_long) pktsend);
                gettimeofday (tp, (struct timezone *) 0);
                srec->snd.tv_sec = htonl ((u_long) tp->tv_sec);
                srec->snd.tv_usec = htonl ((u_long) tp->tv_usec);

	    	/* Send the string to the server */
                outcnt = write (sock, sdata, pktsize);
                if (outcnt < 0) {
		}
		pktsend++;
    	}
    	dcnt = 0;
    	tpole[nt]=msdelay(sleeptime);
   }
// new rpt_cycle need clean np
pktsend=1;
// set up delay in sec !!!!!
ms_iter=(iter_t - 1) *880.0+ 30;
ms1=msdelay(ms_iter);

} /*rpt_cnt_end*/
// start timeout now
raise(SIGALRM);
exit (-1);
} else {
/******** parent = receiver ***********************/
//        printf("I am parent and I will do receiving\n");
    		/* Recv a response */
    		fromSize = (unsigned int)sizeof(struct sockaddr_in);
		rcnt=0;
  while (1) {
	  	//printf("The source is fromsize234 is %u and pktsize is %d\n",
fromSize, pktsize);
    		if ((incnt = recvfrom(sock, rdata, pktsize, 0, (struct sockaddr
*)&src, &fromSize)) <0)
		{
			printf("The number returns is %d and rdata is %s\n",incnt,rdata);
        		DieWithError("recvfrom() failed ");
		}//HERE I AM GETTING AN EINVAL

Sorry for sending such a long code, but a part of it won't make a sense, I
guess.

Thanks in advance.
Varun Sharma






> On Jun 26 17:41, Varun Sharma wrote:
>>
>> Hi,
>>  I have been trying to run the abing code
>> (http://www-iepm.slac.stanford.edu/tools/abing/). It basically set up a
>> UDP client and server and then there are excahnge of UDP packets. I have
>> been running into troubles since when I have been trying to install it.
>>  Firstly the make file had the -lnsl option which it cannot find in
>> cygwin, so I removed it and compiled the code and everything worked fine
>> with the warning that it cannot find the -pthread option.
>>  Then to run the reflector in abing, one has to execute the following
>> commmand.
>> ./abw_rfl -c &
>> ./abing -c
>> ./abw_rfl &
>>
>> But in my case, I get an error when I run ./abing -c saying that
>> revcfrom
>> failed with invalid argument. The code works fine with no error at all
>> in
>> a normal linux distro. I am unable to find out the difference. Even UDP
>> clients and server codes which can be easily downloaded from the net
>> work
>> fine.
>>  I would be really obliged if someone can tell me the problem or some
>> ekind of an experience he or she has on installing and using abing on
>> cygwin.
>
> This would require to get some more details from you besides "recvfrom
> returns EINVAL".  http://cygwin.com/problems.html
>
> Anyway, I have a wild guess.  Windows' recvfrom only understands MSG_OOB
> and MSG_PEEK.  Any other flag value is unsupported and should result in
> recvfrom returning EINVAL.  Maybe that's your problem.  Solution:  Don't
> use flags except MSG_OOB and MSG_PEEK.
>
>
> Corinna
>
> --
> Corinna Vinschen                  Please, send mails regarding Cygwin to
> Cygwin Project Co-Leader          cygwin AT cygwin DOT com
> Red Hat
>
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
>


-- 
Varun Sharma
Computer Science and Engineering
Sophomore
IIT Kanpur

"If electricity comes from electrons, does morality comes from morons"


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019