This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I have implemeted the client server program where the client sends a file to the server. The server uses a fixed port 1500 to receive the data.But the client responds thro some other PORT!!! i WANT BOTH THE CLIENT AND THE SERVER COMMUNICATE THRO SAME PORT COULD U HELP ME IN THIS? Thanks in advance regards Smitha
Well, the Socket class has several four-argument constructors that let you specify the local address and port as well as the remote address and port; just use one of those and then you can specify that the local port should be 1500. Now, I have to ask you why you want to do this? It's not a very common requirement. A very few protocols (like Berkeley lpr) once used privileged client-side ports as a very weak security mechanism -- but these days, that doesn't make any sense. Using a fixed local port means that only one client on the local machine will be able to connect to the remote service at a time; for some kinds of software, this would be a serious impediment.
Well This application I have developed to release it to the customers where the port number that will b purchased by us will b just one. And so we wanted to use just 1 port for both the client as well as the server. Since we cant get more than 1 port for purchase!!! Hope u can get me! Pls reply if u didnt understand
well, Although the server binds to one port to listen ( also called passive port ), when a request comes in, another port ( internally handled ) must be assigned to the incomming connection, for processing ( also called the active port ). After the assignment, the server resumes listening on the passive port. typically for a multi threaded server, that spans a unique thread for each connection, for processing the code would be
Well, in this case, there is only one listening port ( passive port ) and an active port is ramdomly assigned by the n/w layer, as soon as a connection is accepted. You can see this by printing the client sockets attributes,or using tcpdump. Technically, the code fragment above must solve your problem of being restricted to using one port. To fine tune the performance of the server, because too many threads in a system is a problem, you would have to use something like a queue with a non-blocking socket ( see concept of IOCompletionPort, VC++ ). Cheers Lupo