Code Monkey home page Code Monkey logo

python-chat-application's Introduction

Python-Chat-Application

It is a simple project and contains two Python scripts server.py which handles client requests and client.py sends requests and receives responses from the server through socket communication.

Prerequisites To run the Python script, your system must have the following programs/packages installed and the contact number should be saved in your phone (You can use the bulk contact number saving procedure of email). There is a way to save the contact number but cannot send the attachment.

Python 3.8

Approach server.py needed to execute in the terminal. client.py needed to execute from the client machine and enter the hostname or IP address. the server will establish the connection between the server and the client through the socket. now from the server or client text can be sent.

Server Code

Program to accept client request

import socket

s = socket.socket() host = socket.gethostname() print(' Server will start on host : ', host) port = 8080 s.bind((host, port)) print() print('Waiting for connection') print() s.listen(1) conn, addr = s.accept() print(addr, ' Has connected to the server') print() while 1: message = input(str('>> ')) message = message.encode() conn.send(message) print('Sent') print() incoming_message = conn.recv(1024) incoming_message = incoming_message.decode() print(' Client : ', incoming_message) print()

Client Code
# Program to send request to the server

import socket

s = socket.socket() host = input(str('Enter hostname or host IP : ')) port = 8080 s.connect((host, port)) print('Connected to chat server') while 1: incoming_message = s.recv(1024) incoming_message = incoming_message.decode() print(' Server : ', incoming_message) print() message = input(str('>> ')) message = message.encode() s.send(message) print('Sent') print()

python-chat-application's People

Contributors

nikhilkamode avatar

Watchers

 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.