Coder Social home page Coder Social logo

ex-3's Introduction

EX-03 STUDY OF SOCKET PROGRAMMING WITH CLIENT-SERVER MODEL

DATE :09-03-2023

AIM :

To implement socket programming date and time display from client to server using TCPSockets

ALGORITHM :

Server:

  1. Create a server socket and bind it to port.
  2. Listen for new connection and when a connection arrives, accept it.
  3. Send server‟s date and time to the client.
  4. Read client‟s IP address sent by the client.
  5. Display the client details.
  6. Repeat steps 2-5 until the server is terminated.
  7. Close all streams.
  8. Close the server socket.
  9. Stop.

Client:

  1. Create a client socket and connect it to the server‟s port number.
  2. Retrieve its own IP address using built-in function.
  3. Send its address to the server.
  4. Display the date & time sent by the server.
  5. Close the input and output streams.
  6. Close the client socket.
  7. Stop

PROGRAM :

CLIENT :

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("%d/%m/%Y %H:%M:%S").encode())
ack=c.recv(1024).decode()
if ack:
    print(ack)
c.close()

SERVER :

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())

OUTPUT:

Screenshot (98) Screenshot (99)

RESULT: Thus, the program to implement socket programming date and time display from client to server using TCP Sockets was successfully executed.

ex-3's People

Contributors

varshxnx avatar sujathamohankumar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.