Class Notes (835,673)
Canada (509,326)
CSC209H1 (41)
Karen Reid (20)
Lecture

mar22c.docx

1 Page
109 Views
Unlock Document

Department
Computer Science
Course
CSC209H1
Professor
Karen Reid
Semester
Winter

Description
 inetserver.c  inetclient.c 1. #include 1. #include 2. #include 2. #include 3. #include 3. #include 4. #include 4. #include 5. #include /* for getenv */ 5. #include 6. #include 6. #include 7. #include 7. #include 8. #include /* Internet domain header */ 8. 9. 9. #ifndef PORT 10. #ifndef PORT 10. #define PORT 30000 11. #define PORT 30000 11. #endif 12. #endif 12. 13. 13. int main(int argc, char* argv[]) { 14. int main() { 14. int soc; 15. char buf[256], host[256]; 15. char buf[256]; 16. struct sockaddr_in peer, self; 16. struct hostent *hp; 17. unsigned int peer_len = sizeof(peer); 17. 18. 18. struct sockaddr_in peer; 19. self.sin_family = PF_INET; // socket for IPv4 19. peer.sin_family = PF_INET; 20. self.sin_port = htons(PORT); // define port 20. peer.sin_port = htons(PORT); 21. self.sin_addr.s_addr = INADDR_ANY; 21. printf("PORT = %d\n", PORT); 22. bzero(&(self.sin_zero), 8); 22. 23. 23. if (argc != 2) { 24. peer.sin_family = PF_INET; 24. fprintf(stderr, "Usage: %s hostname\n", 25. 25. argv[0]); 26. // set up listening socket soc 26. exit(1); 27. int soc = socket(PF_INET, SOCK_STREAM, 0); 27. } 28. 28. 29. // reuse the port immediately after server terminates 29. // fill in peer address 30. int on = 1; 30. hp = gethostbyname(argv[1]); // argv[1] is address 31. int status = setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, 31. if (hp == NULL) { 32.
More Less

Related notes for CSC209H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit