1234567891011121314151617181920212223242526272829303132333435363738 |
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<unistd.h>
- #include<arpa/inet.h>
- #define port 8081
- int main()
- {
- int sockfd;
- struct sockaddr_in client;
- if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
- perror("socket failed\n");
- client.sin_family = AF_INET;
- client.sin_addr.s_addr = inet_addr("127.0.0.1");
- client.sin_port = htons(port);
- if(connect(sockfd,(struct sockaddr*)&client,sizeof(client))<0)
- perror("connection failed\n");
- else
- printf("connected successfully\n");
- while(1)
- {
- char s[20];
- printf("enter the data to send\n");
- scanf("%s",s);
- send(sockfd,(char*)s,strlen(s),0);
- }
- }
|