To perform a study on Socket Programming.
Socket programming is a crucial aspect of network communication, allowing for data exchange between computers over a network. It forms the backbone of various networked applications, enabling communication between clients and servers. This study explores the fundamental concepts of socket programming, its use cases, and provides a practical example to demonstrate its implementation.
Socket programming involves the use of sockets, which serve as endpoints for communication. A socket is identified by an IP address and a port number, and it facilitates data transfer between a client and a server. The two main types of sockets are Stream Sockets, which provide a reliable, connection-oriented communication, and Datagram Sockets, which are connectionless and suitable for scenarios where reliability is less critical.
• A socket is a software representation of a communication endpoint in a network.
• It is identified by an IP address and a port number.
• Sockets can be classified into two main types: Stream Sockets and Datagram Sockets.
• Stream Sockets provide a reliable, connection-oriented communication, while Datagram Sockets are connectionless and operate in a best-effort mode.
• Socket programming typically follows the client-server model.
• The server listens for incoming connections from clients, while clients initiate connections to the server.
• Servers are passive, waiting for connection requests, and clients are active, initiating communication.
• Transmission Control Protocol (TCP) and Internet Protocol (IP) are the foundational protocols for socket programming.
• TCP provides reliable, connection-oriented communication, ensuring data integrity and order.
• IP facilitates the routing of data between devices in a network.
• Socket programming involves a set of functions provided by the operating system or programming language to create, bind, listen, accept, connect, send, and receive data through sockets.
• Examples of functions include socket(), bind(), listen(), accept(), connect(), send(), and recv().
• Servers create a socket using socket() and bind it to a specific IP address and port using bind().
• They then listen for incoming connections with listen() and accept connections with accept().
• Once a connection is established, servers can send and receive data using send() and recv().
Clients create a socket using socket() and connect to a server using connect(). After establishing a connection, clients can send and receive data using send() and recv().
Socket programming finds applications in various domains, including web development, file transfer protocols, online gaming, and real-time communication. It is the foundation for protocols like HTTP, FTP, and SMTP, which power the internet. Socket programming enables the development of both server and client applications, facilitating the exchange of information between devices in a networked environment.
- Web servers: Web servers use socket programming to handle incoming HTTP requests from clients, serving web pages and content.
- Chat Application: Instant messaging and chat applications use sockets to enable real-time communication between users.
- File Transfer Protocol: Protocols like FTP (File Transfer Protocol) utilize socket programming for transferring files between a client and a server.
- Networked Games: Online multiplayer games rely on socket programming to facilitate communication between game clients and servers.
- RPC mechanisms: which allow processes to execute code on a remote server, often use socket programming for communication.
Developed by : NITHYA D
Reg no : 212223240110
import socket
from datetime import datetime
s=socket.socket()
s.bind(('localhost',8000))
s.listen(5)
c,addr=s.accept()
print("Client Address : ",addr)
now = datetime.now()
c.send(now.strftime("Date: %d/%m/%Y and Time: %H:%M:%S").encode())
ack=c.recv(1024).decode()
if ack:
print(ack)
c.close()
Developed by : NITHYA D
Reg no : 212223240110
import socket
s=socket.socket()
s.connect(('localhost',8000))
print(s.getsockname())
print(s.recv(1024).decode())
s.send("acknowledgement recived from the server".encode())
Thus the study of Socket Programming Completed Successfully.