Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<netinet/in.h>
- #include<sys/socket.h>
- main()
- {
- struct sockaddr_in sa,cli;
- int n,sockfd;
- int len;
- char buff[100];
- sockfd=socket(AF_INET,SOCK_STREAM,0);
- if(sockfd<0)
- {
- printf(“Error in Socket”);
- exit(0);
- }
- else
- printf(“Socket is Opened”);
- bzero(&sa,sizeof(sa));
- sa.sin_family=AF_INET;
- sa.sin_port=htons(5600);
- if(connect(sockfd,(struct sockaddr*)&sa,sizeof(sa))<0)
- {
- printf(“Error in connection failed”);
- exit(0);
- }
- else
- printf(“connected successfully”):
- if(n=read(sockfd,buff,sizeof(buff))<0)
- {
- printf(“Error in Reading”);
- exit(0);
- }
- else
- {
- printf(“Message Read %s”,buff);
- buff[n]=’\0’;
- printf(“%s”,buff);
- }
- }
Add Comment
Please, Sign In to add comment