c - Socket programming port number -


there tutorial not understand. hope can explain me. http://www.tidytutorials.com/2009/12/c-winsock-example-using-client-server.html

in server program, it's port initialised 1101 (line 14)

13.     //the port want server listen on 14.     int host_port= 1101; 

and in client program it's port 1101

12.     //the port , address want connect 13.     int host_port= 1101; 14.     char* host_name="127.0.0.1"; 

now here's question.

is int host_port in client program same int host_port inside server program?

why port number 1101? (i error 111 when change port number 80 or other number 1234)

isnt char* host_name="127.0.0.1"; supposed refer client ip address? why must use loopback address , not 192.x.x.x.

thank you

i realise mistake, run client before server program......... , in client program did not put

serv_addr.sin_addr.s_addr = inaddr_any; <<<<<< 

the server , client port numbers must match. port number part of address of server. if client applies wrong address, i.e. wrong port number or wrong server address, message delivered wrong recipient. postal addresses. if writing friend, have mention street number , city. if put wrong street number, letter reach somewhere else.

and must use port number not in use. 80 known port number; reserved http. if port number used, cannot allocate else. on machine port 80 may in use. not want home street address allocated else or else allocated same house yours. inconvenient. can imagine happen if computers allowed 2 programs use same port number.

you can evict known port number. can shut off web server, if 1 running on machine, , write client/server app use port 80.

you can use 192.xxx addresses. provided firewalls on computers not blocking it. because while loopback loops within computer, 192.xx addressing scheme cause packets go out on lan , come back. may wrong on one, on operating systems. experiment , let know if right or wrong.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -