14. Course Project Details



Hello folks!
Welcome to this last blog of our blog series. In the previous blog we have studied basics of socket programming,Now in this blog we will see the code of project, socket programming based group chat application

Code of the project

1) SERVER code :
import socket
import threading

print("Server Code\n")
class Server:
clients = []
names = []

    def create(self):
        self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.port = 25000
        self.name = input("Enter name : ")
        self.s.bind(('', self.port))
        print("Socket binded to port: " + str(self.port))
        self.chatWindow()
        return

    def sender(self):
        while True:
            msg = input()
            for i in self.clients:
                self.s.sendto(bytes(self.name + " : " + msg, "utf-8"), i)

    def receiver(self):
        while True:
            msg, self.addr = self.s.recvfrom(1024)
            if(self.addr not in self.clients):
                print("Message from " + str(self.addr) + " : " + str(msg.decode("utf-8"))+"\n")
                self.clients.append(self.addr)
                self.names.append(str(msg.decode("utf-8")))
                self.s.sendto(bytes(self.name, "utf-8"), self.addr)
                print("Name sent to "+str(self.addr)+"\n")
            else:
                print(self.names[self.clients.index(self.addr)] +
                      ": " + str(msg.decode("utf-8"))+"\n")
                msg = str(msg.decode("utf-8"))
                for i in self.clients:
                    if(i != self.addr):
                        self.s.sendto(
                            bytes(self.names[self.clients.index(self.addr)]+" : " + msg, "utf-8"), i)

    def chatWindow(self):
        print("Chat Messenger Server\n")
        threadS = threading.Thread(target=self.sender)
        threadR = threading.Thread(target=self.receiver)
        threadS.start()
        threadR.start()

if __name__ == '__main__':
    server = Server()
    server.create()

2) CLIENT code :

import socket
import threading

print("Client Code\n")
class Client:
clients = []
names = []

    def create(self):
        self.name = input("Enter name : ")
        self.ip = socket.gethostbyname(socket.gethostname())
        self.port = 25000
        self.c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        print("Socket binded successfully")
        self.c.sendto(bytes(self.name, "utf-8"), (self.ip, self.port))
        print("Chat Messenger Client\n")
        self.chatWindow()

    def chatWindow(self):
        threadS = threading.Thread(target=self.sender)
        threadR = threading.Thread(target=self.receiver)
        threadS.start()
        threadR.start()

    def sender(self):
        while True:
            msg = bytes(input(), "utf-8")
            self.c.sendto(msg, (self.ip, self.port))

    def receiver(self):
        while True:
            msg, addr = self.c.recvfrom(1024)
            if(addr not in self.clients):
                self.clients.append(addr)
                self.names.append(str(msg.decode("utf-8")))
                print("Message from " + str(addr) + ": Name : " + str(msg.decode("utf-8"))+"\n")
            else:
                print(str(msg.decode("utf-8"))+"\n")

if __name__ == '__main__':
    client = Client()
    client.create()
    client.chatWindow()

The details of this code are explained in links given below


Details of the course project :

Course Project Title:Socket programming based group chat application
Description of project :
Course Project Report Link : Report link
Course Project Presentation Link : Presentation Link


Topic 1:
Presenter's Info:
Student Name : Archit Hiwrekar
Div : K
Roll No : 23
GRNO : gr no 1710994
Topic 1 Video Link : Video link

Topic 2:
Presenter's Info : 
Student Name : Chinmay Kapkar
Div : K
Roll No : 33
GRNO : 1710732
Topic 2 Video Link : Video link

Topic 3:
Presenter's Info : 
Student Name : Hrishikesh Deshpande
Div : K
Roll No : 16
GRNO : 1711063
Topic 3 Video Link :  Video link

Topic 4:
Presenter's Info:
Student Name : Ashutosh Bardapurkar
Div : K
Roll No :5
GRNO :1710459
Topic 4 Video Link : Video link

10 comments: