Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will develop a simple yet secure, and robust concurrent chat system with the following requirements: Extend the BroadcastEchoServer.go (From Lab 3)

In this assignment, you will develop a simple yet secure, and robust concurrent chat system with

the following requirements:

Extend the BroadcastEchoServer.go (From Lab 3) program to become a Chat Server:

A user must be authenticated with username/password

Serve the clients with the following use cases:

Return the list of logged-in users

Send a message to all users (public chat)

Send a message to a specific user (private chat)

Extend the telnet.js (From Lab 3) program to become a Chat Client:

Ask username/password from the user to send to the server for authentication

Print a simple menu for the user to

Execute the functions provided by the server or exit the chat program.

Database and Security

Username/password should be stored in a JSON file at server-side. Passwords must be

hashed.

Data transferred between the clients and the server must be encrypted

EchoServer in GoLang

import (

"fmt"

"net"

"os"

)

const BUFFERSIZE int = 1024

func main() {

if len(os.Args) != 2 {

fmt.Printf("Usage: %s ", os.Args[0])

os.Exit(0)

}

port := os.Args[1]

if len(port) > 5 {

fmt.Println("Invalid port value. Try again!")

os.Exit(1)

}

server, err := net.Listen("tcp", ":"+port)

if err != nil {

fmt.Printf("Cannot listen on port '" + port + "'! ")

os.Exit(2)

}

fmt.Println("EchoServer in GoLang developed by Sagarika Madhavan, SecAD-S19")

fmt.Printf("EchoServer is listening on port '%s' ... ", port)

allClient_conns := make(map[net.Conn]string) //mapping with connection and string

newclient := make(chan net.Conn)

go func() {

for {

client_conn, _ := server.Accept()

//go client_goroutine(client_conn,allClient_conns)

newclient <- client_conn

}

}()

for{

select{

case client_conn := <-newclient:

fmt.Printf("A new client '%s' connected! ", client_conn.RemoteAddr().String())

allClient_conns[client_conn]= client_conn.RemoteAddr().String()

go client_goroutine(client_conn,allClient_conns)

//delete(allClient_conns,client_conn)

//go sendtoAll(allClient_conns,[]byte(welcomemessage))

}

}

}

func client_goroutine(client_conn net.Conn, allClient_conns map[net.Conn]string ) {

fmt.Printf("# clients: %d ",len(allClient_conns))

lostclient :=make(chan net.Conn)

var buffer [BUFFERSIZE]byte

go func(){

for{

byte_received,read_err := client_conn.Read(buffer[0:])

if read_err != nil{

fmt.Println("Error in receiving...,disconnected client,")

lostclient <- client_conn

return

}

data := buffer[0:byte_received]

go sendtoAll(allClient_conns,data)

fmt.Printf("Received data: %sEchoed back! ", buffer)

}

}()

for {

select{

case client_conn := <-lostclient:

//handling for the event

delete(allClient_conns,client_conn)

}

}

}

func sendtoAll(allClient_conns map[net.Conn]string, data []byte){

fmt.Printf("# clients: %d ",len(allClient_conns))

for client_conn, _ := range allClient_conns {

_, write_err := client_conn.Write(data)

if write_err != nil {

fmt.Println("Error in sending...")

return

}

}

}

Develop a chat server modifying the above code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

To solve p + 3q = 5z + tan( y - 3x)

Answered: 1 week ago