Article 4Y5XC simple server in C recive probblem

simple server in C recive probblem

by
end
from LinuxQuestions.org on (#4Y5XC)
hi, this server was working and i try put select and non blocking and obviously i something change in process and now not working

errno sad: 88
strerrno sad: socket operation on non socket

Code:#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include<arpa/inet.h>
#include <errno.h>
int main()
{
int sockett;
char sndmsg[1024]="hi";
char rcvmsg[1024];
struct sockaddr_in server, connstorage;
int len;
int opt=1;
int conn;

sockett=socket(AF_INET,SOCK_STREAM,0);

setsockopt(sockett,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt) );

server.sin_family=AF_INET;
server.sin_port=htons(80);
server.sin_addr.s_addr=inet_addr("127.0.0.1");

if ((bind(sockett,(struct sockaddr *) &server,sizeof(server))) != 0)
{
printf("Bind failed\n");
}

else
printf("Bind success\n");

if ((listen(sockett,5)) < 0)
{
printf("Listen failed\n");
}

else
printf("Listen success\n");

len=sizeof(connstorage);

if(conn=accept(sockett,(struct sockaddr *)&connstorage,&len) > 0)
{
printf("Accepted\n");
}
else
printf("Notaccepted\n");

if(recv(conn, rcvmsg, 1024,0 ) < 0)
{
printf("RCV_PROBLLEM\n");
printf("%d\n",errno);
printf("err desc: %s\n",strerror(errno));
}
else
printf("%s\n",rcvmsg);

}latest?d=yIl2AUoC8zA latest?i=GlbN8Un259g:Bje1pqbQUD8:F7zBnMy latest?i=GlbN8Un259g:Bje1pqbQUD8:V_sGLiP latest?d=qj6IDK7rITs latest?i=GlbN8Un259g:Bje1pqbQUD8:gIN9vFwGlbN8Un259g
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments