hi
i 'm new to socket programming trying to write a server which sends message(by getting a string using fgets in a while loop ) to clients its sends the first messge but didnot send the next message also it shows bind error if i run it again from the same terminal
client connects using telnet
please help
35,6 63%Code:#include<unistd.h> int main() { int sock,new; struct sockaddr_in server,client; int len=sizeof(struct sockaddr); char msg[50]="first tcp sockets programme\n"; if ((sock=socket(AF_INET,SOCK_STREAM,0))==-1) { perror("socket:"); exit(-1); } //now bind the server port server.sin_family=AF_INET; server.sin_port =htons(9000); server.sin_addr.s_addr=INADDR_ANY; bzero(&server.sin_zero, 8); if ((bind(sock,(struct sockaddr *)&server,sizeof(struct sockaddr) ))==-1) {perror("bind error:"); exit(-1); } listen(sock,2); // listen seldom gines error while(1) {if((new=accept(sock,(struct sockaddr *)&client,&len))==-1) {perror("accept:"); exit(-1); } //sending message fgets(msg ,20,stdin); send(new,msg,strlen(msg),0); } close(new);//describe the client socket close(sock); }



LinkBack URL
About LinkBacks



