12345678910111213141516171819202122232425262728293031323334353637 |
- #include<stdio.h>
- #include<netinet/in.h>
- #include<sys/socket.h>
- #include<sys/types.h>
- #include<unistd.h>
- #include<string.h>
- int main()
- {
- int sd;
- int port;
- struct sockaddr_in cli;
- char msg[80],add[80];
- sd=socket(AF_INET,SOCK_STREAM,0);
- bzero(&cli,sizeof(cli));
- printf("enter the port no");
- scanf("%d",&port);
- cli.sin_family=AF_INET;
- cli.sin_port=htons(port);
- printf("enter the ip address");
- scanf("%s",add);
- cli.sin_addr.s_addr=inet_addr(add);
- int con=connect(sd,(struct sockaddr*)&cli,sizeof(cli));
- while(1)
- {
-
- memset(msg,'\0',sizeof(msg));
- printf("\nmsg from server\n");
- read(sd,msg,10);
- printf("%s",msg);
- printf("\nenter the msg to send\n");
- scanf("%s",msg);
- write(sd,msg,strlen(msg));
- }
- return 0;
- }
|