PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > Socket Problem............
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Socket Problem............

Réponse
 
LinkBack Outils de la discussion
Vieux 19/10/2007, 19h12   #1 (permalink)
Clement
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Socket Problem............

Please me.......
I am getting blocked in bind() system call.......

i don't know why

can you please any one tell me why........


#include<stdio.h>
#include<sys/un.h>
#include<sys/types.h>
#include<sys/socket.h>
#define SOCK_PATH "mysock1"
void error(char *);
main()
{
printf("OK");
int sockfd,newsockfd,serverlen,clilen,n;
struct sockaddr_un cli_addr,serv_addr;
char buf[80];
printf("Ok");
if((sockfd=socket(AF_UNIX,SOCK_STREAM,0))<0)
perror("creating socket");
serv_addr.sun_family=AF_UNIX;
printf("OK");
unlink(SOCK_PATH);
strcpy(serv_addr.sun_path,SOCK_PATH);
if(bind(sockfd,(struct sockaddr
*)&serv_addr,sizeof(serv_addr))<0)
perror("binding socket");
listen(sockfd,1);
clilen=sizeof(cli_addr);
newsockfd=accept(sockfd,(struct sockaddr
*)&cli_addr,&clilen);
printf("Ok\n");
if(newsockfd<0)
error("accepting");
for(;
{
printf("Waiting for Client......\n");
read(newsockfd,buf,sizeof(buf));
printf("**CLIENT** :%s",buf);
if(strcmp("end\n",buf)==0)
{
printf("Disconnecting\n");
exit(0);
}
printf("**SERVER** :");
fgets(buf,sizeof(buf),stdin);
write(newsockfd,buf,sizeof(buf));
}
}
void error(char *msg)
{
perror(msg);
exit(0);
}

  Réponse avec citation
Vieux 19/10/2007, 19h21   #2 (permalink)
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Socket Problem............

Clement wrote:

> Please me.......
> I am getting blocked in bind() system call.......
>
> i don't know why
>
> can you please any one tell me why........


<snip>

Since bind() is not defined by ISO C, you should try a group specific to
your system, most likely <comp.unix.programmer>

  Réponse avec citation
Vieux 20/10/2007, 14h30   #3 (permalink)
husterk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Socket Problem............

On Oct 19, 2:12 pm, Clement <jeba.r...@gmail.com> wrote:
> Please me.......
> I am getting blocked in bind() system call.......
>
> i don't know why
>
> can you please any one tell me why........
>
> #include<stdio.h>
> #include<sys/un.h>
> #include<sys/types.h>
> #include<sys/socket.h>
> #define SOCK_PATH "mysock1"
> void error(char *);
> main()
> {
> printf("OK");
> int sockfd,newsockfd,serverlen,clilen,n;
> struct sockaddr_un cli_addr,serv_addr;
> char buf[80];
> printf("Ok");
> if((sockfd=socket(AF_UNIX,SOCK_STREAM,0))<0)
> perror("creating socket");
> serv_addr.sun_family=AF_UNIX;
> printf("OK");
> unlink(SOCK_PATH);
> strcpy(serv_addr.sun_path,SOCK_PATH);
> if(bind(sockfd,(struct sockaddr
> *)&serv_addr,sizeof(serv_addr))<0)
> perror("binding socket");
> listen(sockfd,1);
> clilen=sizeof(cli_addr);
> newsockfd=accept(sockfd,(struct sockaddr
> *)&cli_addr,&clilen);
> printf("Ok\n");
> if(newsockfd<0)
> error("accepting");
> for(;
> {
> printf("Waiting for Client......\n");
> read(newsockfd,buf,sizeof(buf));
> printf("**CLIENT** :%s",buf);
> if(strcmp("end\n",buf)==0)
> {
> printf("Disconnecting\n");
> exit(0);
> }
> printf("**SERVER** :");
> fgets(buf,sizeof(buf),stdin);
> write(newsockfd,buf,sizeof(buf));
> }}
>
> void error(char *msg)
> {
> perror(msg);
> exit(0);
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -


Try configuring your socket for non-blocking (i.e. asynchronous)
operation prior to calling the bind function. This will allow you to
place a timeout on the bind() call which will return some type of
error code instead of just hanging your system. You can then review
this error code to determine what the problem is. Don't forget to
change the socket back to blocking.

Keith
http://www.doubleblackdesign.com

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h29.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10683 seconds with 11 queries