Internet Networking: Socket Programming
Internet Networking: Socket Programming
SOCKET PROGRAMMING
• Understand the concept of socket
• Learn how to send & receive data through sockets
• Implement network clients & servers
Recap of the last lecture(18/01/2023)
• INTERNET: the global network that links
millions of computers.
• Internet is not same as web
• A web is one of many internet services
– Email, FTP, Telnet, VoIP, Newsgroup and more
• Networking models: TCP/IP, OSI and more
Transmission Channel
• Physical characteristics of transmissions on
network differs widely
• Connection using cables – coaxial, twisted
pair, fibre optics
• Connection using DSL modem – send signals
across a telephone wire encoded as tones
• Connection using wireless – transmit a
modulated radio frequency
Internet Protocol (IP)
• Protocol is a set of rules that governs the
transmission of network information.
– application data, network data
• Example of protocols: Microsoft Networking,
Novell Netware, AppleTalk, and Ethernet
• IP was developed for LAN to communicate with
each other
• It has become the basis for connecting computers
around the world
• IP addresses are denoted by sequence of four
numbers e.g. 130.65.86.66
TCP/IP
• The IP has just one function—to attempt to
deliver data from one computer to another
across the Internet
• TCP/IP: a pair of communication protocols
used to establish reliable transmission of data
between two computers on the Internet
• Exceptions are “streaming media” services,
However, the most popular Internet services—
the World Wide Web and e-mail—use TCP.)
TCP/IP
• A TCP connection requires the Internet
addresses and port numbers of both end
points.
• TCP uses port numbers for this purpose. A port
number is an integer between 0 and 65,535
• Some applications use “well-known” port
numbers
• web servers use port 80, mail servers running
the Post Office Protocol (POP) use port 110.
TCP/IP
• TCP packets, therefore, must contain
– The Internet address and port number of the
recipient (destination)
– The Internet address and port number of the
sender (source)
Application level protocol
• Each Internet application has a different
application protocol, which describes how the
data for that particular application are
transmitted
• HTTP: the Hypertext Transfer Protocol which
is used for the World Wide Web
• Suppose you type a web address, called a
Uniform Resource Locator such as
http://horstmann.com/index.html
Application level protocol
• Post Office Protocol (POP), is used to
download received messages from e-mail
servers
• To send messages, use another protocol called
the Simple Mail Transfer Protocol (SMTP)
• Mention other application level protocol?
Socket and ServerSocket
• Socket and ServerSocket classes are used for
connection-oriented socket programming (TCP
connection)
• DatagramSocket and DatagramPacket classes
are used for connection-less socket
programming (UDP connection)
A Client program
• A socket is an object that encapsulates a TCP
connection
• To communicate with the other end point of
the connection, use the input and output
streams attached to the socket
• The client in socket programming must know
two information:
– IP Address of Server, and
– Port number
Socket class
• A socket is simply an endpoint for
communications between the machines. The
Socket class can be used to create a socket.
• Important methods
Method Description