I'm sorry if I am unclear! I am having a very hard time putting my thoughts/questions into words at the moment!! I know how to write the server. I can code it in 5 minutes. I am now trying to learn how to write the client. Which is not a problem. I just want to know why i have to get the port number from the command line before creating the socket on the client. Or do I? I am using this tutorial as a reference Linux Howtos: C/C++ -> Sockets Tutorial As to where on the server, it can be done after creating the socket. What i am asking is, is there a specific place/time i need to get the ip or port number? Or can i get the port number from the command line as long as its done before i connect to the server.
Example=>
WHY CANT THIS
Code:
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
BE THIS
Code:
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
portno = atoi(argv[2]);
OR EVEN THIS
Code:
bzero((char *) &serv_addr, sizeof(serv_addr));
portno = atoi(argv[2]);
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
Is there a certain standard for the placement of them?