Guest User

Untitled

a guest
May 26th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include<netinet/in.h>
  2. #include<sys/socket.h>
  3. main()
  4. {
  5. struct sockaddr_in sa,cli;
  6. int n,sockfd;
  7. int len;
  8. char buff[100];
  9. sockfd=socket(AF_INET,SOCK_STREAM,0);
  10. if(sockfd<0)
  11. {
  12. printf(“Error in Socket”);
  13. exit(0);
  14. }
  15. else
  16. printf(“Socket is Opened”);
  17. bzero(&sa,sizeof(sa));
  18. sa.sin_family=AF_INET;
  19. sa.sin_port=htons(5600);
  20. if(connect(sockfd,(struct sockaddr*)&sa,sizeof(sa))<0)
  21. {
  22. printf(“Error in connection failed”);
  23. exit(0);
  24. }
  25. else
  26. printf(“connected successfully”):
  27. if(n=read(sockfd,buff,sizeof(buff))<0)
  28. {
  29. printf(“Error in Reading”);
  30. exit(0);
  31. }
  32. else
  33. {
  34. printf(“Message Read %s”,buff);
  35. buff[n]=’\0’;
  36. printf(“%s”,buff);
  37. }
  38. }
Add Comment
Please, Sign In to add comment