C Socket Programming for stdin
In C socket programming, I have to read from keyboard and accept client
socket creation . The socket connection is created successfully but the
fails to take input from keyboard. Below is code snippet.
int listener; fd_set readfds;
listener=serverConnect(listener,serveraddr,yes);
FD_SET(listener, &readfds);
FD_SET(STDIN, &readfds);
fdmax = listener;
addrlen=sizeof(clientaddr);
for(;;)
{
select(fdmax+1, &readfds, NULL, NULL, NULL);
printf("$");
if(FD_ISSET(listener, &readfds))
{
if((newfd = accept(listener, (struct sockaddr *)&clientaddr,
&addrlen)) == -1)
{
perror("Server-accept() error\n");
}
else printf("Connection is done\n");
}
if (FD_ISSET(STDIN, &readfds))
{
printf("$");
scanf("%s",command1,command2,command3);
printf("The command entered is: %s\n",command1);
if (strcmp(command1, "MYIP")==0)
{
printf("Get ip address\n");
myip();
fflush(stdout);
}
No comments:
Post a Comment