LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-11-2004, 12:01 PM   #1
sheni
LQ Newbie
 
Registered: Nov 2004
Posts: 1

Rep: Reputation: 0
bind : Address already in use


hi all,

I'm trying to learn socket programming.
whenever i run my server it runs properly for the first time, but the second time it says bind: Address already in use. i cant run my server unless i restart my comp. my client program is working fine
please help!

here is the code

bzero((char*) &serv_addr,sizeof(serv_addr));
serv_addr.sin_family=AF_INET;
serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
serv_addr.sin_port=htons(SERV_TCP_PORT);

if(bind(sockfd,(struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
{
perror("bind");
exit(1);

}

listen(sockfd,5);
printf("success\n");
for( ; ; )
{
clilen=sizeof(cli_addr);
newsockfd=accept(sockfd,(struct sockaddr *)&cli_addr, &clilen);

if(newsockfd<0)
printf("server accept error");

if((chpid=fork())<0)
printf("server fork error");

else if(chpid!=0)
{
close(sockfd);
printf("child serving client\n");
if((num_bytes= recv(newsockfd,revarr,99,0))== -1)
{
perror("recv");
exit(0);
}
}

close(newsockfd);
}
}
 
Old 11-11-2004, 12:41 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
You can't run more than one service on the same port.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:443 bruvajon Linux - Software 34 11-30-2011 03:08 PM
how can i remove an address bind sibu_rajappan Linux - Networking 0 12-24-2004 01:50 AM
sun-dr/tcp: bind: Address already in use choonseng Solaris / OpenSolaris 2 10-18-2004 02:48 AM
cannot bind to socket: address already in use exfacior Linux - Wireless Networking 0 09-27-2004 12:34 PM
Help me with this socket address bind program. rnice Linux - Networking 0 09-17-2004 07:33 PM


All times are GMT -5. The time now is 04:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration