RalphG
asked on
Set both LOCAL and TARGET port on socket... (C not C++ - Windows XP Pro - LCC Compiler)
Hi everyone!
I have written a socket server program that is working just fine. However, I want to be able to go OUT through my firewall on one specific port "6190" and hit the target server program on port "62781".
I can hit the target server program on port "62781" fine and establish a working connection great but I want to go out on this specific local port "6190" and not just whatever port Windows slaps me on!
Hope someone has a clue as I seem to have exhausted my search words in google.
Thanks, Ralph.
I have written a socket server program that is working just fine. However, I want to be able to go OUT through my firewall on one specific port "6190" and hit the target server program on port "62781".
I can hit the target server program on port "62781" fine and establish a working connection great but I want to go out on this specific local port "6190" and not just whatever port Windows slaps me on!
Hope someone has a clue as I seem to have exhausted my search words in google.
Thanks, Ralph.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Alexscheele you are a life saver!
Thanks for your quick reply and for taking the time to actually write a coded example.
I changed my code to include the initial "bind" and it worked a treat.
I checked the lot with netstat and my server program also returns the port that the client left on and all is well.
Cannot thank you enough but here's another one anyway.
Thanks Ralph.
Thanks for your quick reply and for taking the time to actually write a coded example.
I changed my code to include the initial "bind" and it worked a treat.
I checked the lot with netstat and my server program also returns the port that the client left on and all is well.
Cannot thank you enough but here's another one anyway.
Thanks Ralph.
ASKER
client_s = socket(AF_INET, SOCK_STREAM, 0);
server_addr.sin_family = AF_INET; // Address family to use
server_addr.sin_port = htons(PORT_NUM); // Port num to use
server_addr.sin_addr.s_add
if (connect(client_s, (struct sockaddr *)&server_addr, sizeof(server_addr)) == 0){
printf("Connected to Server Program\n"); ...