#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <string.h>
#include <netdb.h>
#include <signal.h>
#include <poll.h>
#include <pthread.h>
#include <fcntl.h>
Go to the source code of this file.
Defines | |
#define | BUFFER 4096 |
#define | MSG_SIZE 80 |
#define | MAX_CLIENTS 95 |
#define | MYPORT 7400 |
Functions | |
void | display_row () |
void | LoginPage () |
void | insertCombo () |
void | chat_Page () |
void | friends_Page () |
void | newUser () |
void | connectToServer () |
gint | destroyapp (GtkWidget *widget, gpointer gdata) |
void | createButton_clicked (GtkWidget *widget, gpointer gdata) |
void | newUserButton_clicked (GtkWidget *widget, gpointer gdata) |
void | send_clicked (GtkWidget *widget, gpointer gdata) |
void | view_clicked (GtkWidget *widget, gpointer gdata) |
void | signout_clicked (GtkWidget *widget, gpointer gdata) |
void | sendPhoto (char fname[]) |
void | sendReq_clicked (GtkWidget *widget, gpointer gdata) |
void | getPath_clicked (GtkWidget *widget, gpointer gdata) |
void | sendPhoto_clicked (GtkWidget *widget, gpointer gdata) |
void | addList (char str[]) |
void | insertAll () |
void | removeFrnd (char *str) |
void | newPhotoPage (char fname[], char last[]) |
void | addtext (int n, char *msg, char *name) |
void * | cont () |
void | mainPage () |
void | Read () |
void | subButton_clicked (GtkWidget *widget, gpointer gdata) |
int | main (int argc, char *argv[]) |
Variables | |
char | loginName [100] |
char | password [100] |
char | type [100] |
char | history [500] |
char | hostname [MSG_SIZE] |
char | Rmsg [MSG_SIZE] |
int | friends [100] |
int | n |
int | num = 0 |
char | fList [100][100] |
int | opened [100] |
char | pFriend [100] |
int | fp |
int | size = 150 |
int | r |
int | status = -1 |
gchar | file [100] |
GList * | glist2 = NULL |
int | sockfd |
int | myID |
int | port |
GtkWidget * | windowSendPhoto |
GtkWidget * | label1 |
GtkWidget * | windowNewPhoto |
GtkWidget * | image |
GtkWidget * | textMsg |
GtkWidget * | combo |
GtkListStore * | store |
GtkTreeIter | iter |
GtkCellRenderer * | cell |
GtkWidget * | window5 |
GtkWidget * | window4 |
GtkWidget * | Login |
GtkWidget * | window |
GtkWidget * | window2 |
GtkWidget * | textName |
GtkWidget * | text2 |
GtkWidget * | text3 |
GtkWidget * | text4 |
GtkWidget * | comboQuestion |
GtkWidget * | text6 |
GtkWidget * | label |
GtkWidget * | window3 |
GtkTextIter | iter2 [20] |
GtkTextBuffer * | buffer [20] |
GtkWidget * | text1 |
GtkWidget * | windowView |
GtkWidget * | window10 |
GtkTextBuffer * | bufferView |
GtkTextIter | iterView |
void addList | ( | char | str[] | ) |
void addtext | ( | int | n, | |
char * | msg, | |||
char * | name | |||
) |
void chat_Page | ( | ) |
This function creates GTK for window the users to communicate through messages and send photos.When user want to send a message to another client message should typed in the text box provided and then click send button. OPen the chat window on both sides while sending the messages between the clients.
Definition at line 552 of file Client.c.
References buffer, fList, iter2, label, loginName, num, opened, send_clicked(), sendPhoto_clicked(), text1, textMsg, view_clicked(), and window4.
void connectToServer | ( | ) |
This function is used to connect to the server. socket() create a socket for client. Connect()try to connect to server port using socket. The function socket take three arguments. first of them is socket to be used to connect to server. Second is address of server_address structure type casted as (struct sockaddr *). Third is sizeof() server_address structure. This size is important as we send the address of struct so connect function does not knows what is the length of structure. Also, since same connect is used to connect to ipv6 servers too, connect() internally cannot do sizeof(struct sockaddr_in) to find the size of socket.
Definition at line 1065 of file Client.c.
References hostname, port, and sockfd.
Referenced by createButton_clicked(), and subButton_clicked().
void* cont | ( | ) |
This function is used to receive the message from the server. If the message contains "Friend" stores the client to an array. If the message contains "MSG" the message recieved to the receiver client If the message contains "XClient" indicating client is shutting down. If the message contains "History" displays the chat history of the current client. If the message contains "PHOTO" photo is sended to the client. If the message contains "ACCEPTED" the client is accepted to receive photo. If the message contains "REJECTED" stop sending the photo.
Definition at line 737 of file Client.c.
References addList(), addtext(), BUFFER, fList, fp, friends, history, msg, newPhotoPage(), num, removeFrnd(), Rmsg, and sockfd.
Referenced by mainPage().
void createButton_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
This function called when create button is clicked on the new user window .It retrieves all the values from the button and sends this information to server.
Definition at line 102 of file Client.c.
References comboQuestion, connectToServer(), loginName, LoginPage(), msg, n, newUser(), sockfd, text2, text3, text4, text6, textName, type, and window2.
Referenced by newUser().
gint destroyapp | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
This function destroys the window created by GTK
Definition at line 89 of file Client.c.
Referenced by LoginPage(), mainPage(), newUser(), and sendPhoto_clicked().
void display_row | ( | ) |
void friends_Page | ( | ) |
void getPath_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
A filename including the path is retrieved from gtk_file_chooser_button when user select a file and click open button.
Definition at line 460 of file Client.c.
References file.
Referenced by sendPhoto_clicked().
void insertAll | ( | ) |
void insertCombo | ( | ) |
void LoginPage | ( | ) |
This function is used to create gtk interface for opening the Login page. This page contains Loginname and Password.
Definition at line 1191 of file Client.c.
References destroyapp(), label1, newUserButton_clicked(), subButton_clicked(), text2, textName, and window.
Referenced by createButton_clicked(), main(), and subButton_clicked().
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Used to create a tcp messenger server.
argc | number of command line arguments passed to the program including program name itself. | |
argv | array of command line arguments. This client program receives 2 arguments.First argument is port number and second one is hostname.if no port number it assigns default port as MYPORT |
Definition at line 1254 of file Client.c.
References hostname, LoginPage(), MYPORT, opened, and port.
void mainPage | ( | ) |
This function is used to create the gtk window for contacting the friends ,send messages,send photos. The list of friends are added to the combo box.Selecting the user generates selection_changed signal to the chat page.
Definition at line 880 of file Client.c.
References cell, cont(), destroyapp(), insertCombo(), label1, loginName, r, signout_clicked(), store, and window3.
Referenced by subButton_clicked().
void newPhotoPage | ( | char | fname[], | |
char | last[] | |||
) |
void newUser | ( | ) |
This function creates a gtk window for new user to create his/her account.This function allows to enter loginname,password ,Question and answer to remember the password etc.
Definition at line 182 of file Client.c.
References comboQuestion, createButton_clicked(), destroyapp(), label1, text2, text3, text4, text6, textName, window, and window2.
Referenced by createButton_clicked(), and newUserButton_clicked().
void newUserButton_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
Calls the function newUser() when new user button is clicked on the login page
Definition at line 298 of file Client.c.
References newUser().
Referenced by LoginPage().
void Read | ( | ) |
void removeFrnd | ( | char * | str | ) |
void send_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
void sendPhoto | ( | char | fname[] | ) |
void sendPhoto_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
when user clicks send photo in the chat_Page() a window is created to choose the file for sending.User selects the approriate photo and click send option.
Definition at line 472 of file Client.c.
References destroyapp(), getPath_clicked(), sendReq_clicked(), and windowSendPhoto.
Referenced by chat_Page().
void sendReq_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
This function sends the message to the server to pass the request to the client to accept/reject photo.
Definition at line 428 of file Client.c.
References file, fp, loginName, msg, sendPhoto(), sockfd, and windowSendPhoto.
Referenced by sendPhoto_clicked().
void signout_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
void subButton_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
This function is used to check the valid user or not. It sends the loginname and password to server.It receives the message from server.If valid user call the function mainPage(). If not valid user again it calls the Loginpage().
Definition at line 1124 of file Client.c.
References BUFFER, connectToServer(), loginName, LoginPage(), mainPage(), msg, myID, password, Read(), sockfd, text2, textName, and window.
Referenced by LoginPage().
void view_clicked | ( | GtkWidget * | widget, | |
gpointer | gdata | |||
) |
GtkTextBuffer* buffer[20] |
GtkTextBuffer* bufferView |
GtkCellRenderer* cell |
GtkWidget* comboQuestion |
gchar file[100] |
char fList[100][100] |
Definition at line 39 of file Client.c.
Referenced by chat_Page(), cont(), insertAll(), insertCombo(), removeFrnd(), and send_clicked().
int fp |
Definition at line 42 of file Client.c.
Referenced by cont(), newPhotoPage(), sendPhoto(), and sendReq_clicked().
char history[500] |
char hostname[MSG_SIZE] |
GtkTextIter iter2[20] |
GtkWidget* label |
GtkWidget* label1 |
char loginName[100] |
int myID |
int n |
int port |
int r |
char Rmsg[MSG_SIZE] |
int size = 150 |
int sockfd |
Definition at line 48 of file Client.c.
Referenced by connectToServer(), cont(), createButton_clicked(), Read(), send_clicked(), sendPhoto(), sendReq_clicked(), signout_clicked(), subButton_clicked(), and view_clicked().
GtkListStore* store |
Definition at line 60 of file Client.c.
Referenced by addList(), insertAll(), insertCombo(), mainPage(), and removeFrnd().
GtkWidget* text1 |
GtkWidget* text2 |
Definition at line 69 of file Client.c.
Referenced by createButton_clicked(), LoginPage(), newUser(), and subButton_clicked().
GtkWidget* text3 |
GtkWidget* text4 |
GtkWidget* text6 |
GtkWidget* textMsg |
GtkWidget* textName |
Definition at line 68 of file Client.c.
Referenced by createButton_clicked(), LoginPage(), newUser(), and subButton_clicked().
char type[100] |
GtkWidget* window |
Definition at line 66 of file Client.c.
Referenced by LoginPage(), newUser(), and subButton_clicked().
GtkWidget* window2 |
GtkWidget* window3 |
GtkWidget* window4 |
GtkWidget* windowNewPhoto |
GtkWidget* windowSendPhoto |
GtkWidget* windowView |