Saturday, 24 March 2012

TCP Ports

Welcome to Technology
The port numbers from 0 to 255 are well-known ports, and the use of these port numbers in your application is highly discouraged. Many well-known services you use have assigned port numbers in this range. Service Name Port Number ftp 21 telenet 23 www-http 80 irc 194 Table 1 – Well Known Ports In recent years the range for assigned ports managed by IANA (Internet Assigned Numbers Authority) has been expanded to the range of 0 – 1023. To get the most recent listing of assigned port numbers, you can view the latest RFC 1700 at: http://www.faqs.org/rfcs/rfc1700.html In order for 2 machines to be able to communicate they need to be using the same type of sockets, both have to be TCP or UDP. On Windows, the socket definition is defined in the header file or . Our program will be using Winsock 2.2 so we will need to include and link with WS2_32.lib Opening and closing a socket To create a TCP/IP socket, we use the socket( ) API. SOCKET hSock = socket( AF_INET, SOCK_STREAM, IPPROTO_IP ); If the socket API fails, it will return a value of INVALID_SOCKET, otherwise it will return a descriptor value that we will need to use when referring to this socket. Once we are done with the socket we must remember to call the closesocket( ) API. closesocket( hSock ); Before we can begin to use any socket API in Windows we need to initialize the socket library, this is done by making a call to WSAStartup( )

No comments:

Post a Comment