Client.c File Reference

#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


Define Documentation

#define BUFFER   4096

Definition at line 18 of file Client.c.

#define MAX_CLIENTS   95

Definition at line 20 of file Client.c.

#define MSG_SIZE   80

Definition at line 19 of file Client.c.

#define MYPORT   7400

Definition at line 21 of file Client.c.


Function Documentation

void addList ( char  str[]  ) 

Deleted the client from the combo box when remove friend from the contact list.

Definition at line 656 of file Client.c.

References store.

Referenced by cont().

void addtext ( int  n,
char *  msg,
char *  name 
)

This function adds the message to the TextBuffer

Definition at line 719 of file Client.c.

References buffer, and iter2.

Referenced by cont().

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

This function checks the loginname and pasword entered by the user with data in the database.If it matches set success=0 else set success=1;

Definition at line 84 of file Server.c.

References loginName, password, SId, sqlrow, success, and value.

Referenced by loginFn().

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

Definition at line 663 of file Client.c.

References fList, num, and store.

Referenced by removeFrnd().

void insertCombo (  ) 

This function is used to append list of clients who are login to the combo box.

Definition at line 1003 of file Client.c.

References fList, num, Rmsg, and store.

Referenced by mainPage().

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.

Parameters:
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[] 
)

This function opens a file at receiver client to view the photo.

Definition at line 705 of file Client.c.

References fp.

Referenced by cont().

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

It reads the message from the server.

Definition at line 1029 of file Client.c.

References BUFFER, r, Rmsg, and sockfd.

Referenced by subButton_clicked().

void removeFrnd ( char *  str  ) 

Remove friend who signout from the combo box of all the clients.

Definition at line 680 of file Client.c.

References fList, insertAll(), num, and store.

Referenced by cont().

void send_clicked ( GtkWidget *  widget,
gpointer  gdata 
)

This function sends the message typed in the TextBuffer to the server.

Definition at line 310 of file Client.c.

References buffer, fList, iter2, loginName, num, sockfd, and textMsg.

Referenced by chat_Page().

void sendPhoto ( char  fname[]  ) 

Sends the photo to the client through the server if he accepts the photo request

Definition at line 383 of file Client.c.

References fp, loginName, msg, n, r, size, and sockfd.

Referenced by sendReq_clicked().

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 
)

This function sends a message to server that client is shutting down

Definition at line 368 of file Client.c.

References loginName, msg, and sockfd.

Referenced by mainPage().

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 
)

This function sends the request to the server to view the history This function creates a window at the client with the TextBuffer to view the history.

Definition at line 351 of file Client.c.

References history, loginName, msg, and sockfd.

Referenced by chat_Page().


Variable Documentation

GtkTextBuffer* buffer[20]

Definition at line 77 of file Client.c.

Referenced by addtext(), chat_Page(), and send_clicked().

GtkTextBuffer* bufferView

Definition at line 81 of file Client.c.

GtkCellRenderer* cell

Definition at line 62 of file Client.c.

Referenced by mainPage().

GtkWidget* combo

Definition at line 59 of file Client.c.

GtkWidget* comboQuestion

Definition at line 72 of file Client.c.

Referenced by createButton_clicked(), and newUser().

gchar file[100]

Definition at line 44 of file Client.c.

Referenced by getPath_clicked(), and sendReq_clicked().

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

int friends[100]

Definition at line 38 of file Client.c.

GList* glist2 = NULL

Definition at line 45 of file Client.c.

char history[500]

Definition at line 36 of file Client.c.

Referenced by cont(), main(), and view_clicked().

char hostname[MSG_SIZE]

Definition at line 37 of file Client.c.

Referenced by connectToServer(), and main().

GtkWidget* image

Definition at line 57 of file Client.c.

GtkTreeIter iter

Definition at line 61 of file Client.c.

GtkTextIter iter2[20]

Definition at line 76 of file Client.c.

Referenced by addtext(), chat_Page(), and send_clicked().

GtkTextIter iterView

Definition at line 82 of file Client.c.

GtkWidget* label

Definition at line 74 of file Client.c.

Referenced by chat_Page().

GtkWidget* label1

Definition at line 55 of file Client.c.

Referenced by LoginPage(), mainPage(), and newUser().

GtkWidget* Login

Definition at line 65 of file Client.c.

char loginName[100]

String loginName stores the logniname of client.

Definition at line 35 of file Client.c.

int myID

Definition at line 49 of file Client.c.

Referenced by subButton_clicked().

int n

Definition at line 38 of file Client.c.

Referenced by createButton_clicked(), and sendPhoto().

int num = 0

Definition at line 38 of file Client.c.

int opened[100]

Definition at line 40 of file Client.c.

char password[100]

Definition at line 35 of file Client.c.

char pFriend[100]

Definition at line 41 of file Client.c.

int port

Definition at line 50 of file Client.c.

Referenced by connectToServer(), and main().

int r

Definition at line 42 of file Client.c.

Referenced by mainPage(), Read(), and sendPhoto().

char Rmsg[MSG_SIZE]

Definition at line 37 of file Client.c.

Referenced by cont(), insertCombo(), and Read().

int size = 150

Definition at line 42 of file Client.c.

Referenced by sendPhoto().

int sockfd

int status = -1

Definition at line 43 of file Client.c.

GtkListStore* store

Definition at line 60 of file Client.c.

Referenced by addList(), insertAll(), insertCombo(), mainPage(), and removeFrnd().

GtkWidget* text1

Definition at line 78 of file Client.c.

Referenced by chat_Page().

GtkWidget* text2

Definition at line 69 of file Client.c.

Referenced by createButton_clicked(), LoginPage(), newUser(), and subButton_clicked().

GtkWidget* text3

Definition at line 70 of file Client.c.

Referenced by createButton_clicked(), and newUser().

GtkWidget* text4

Definition at line 71 of file Client.c.

Referenced by createButton_clicked(), and newUser().

GtkWidget* text6

Definition at line 73 of file Client.c.

Referenced by createButton_clicked(), and newUser().

GtkWidget* textMsg

Definition at line 58 of file Client.c.

Referenced by chat_Page(), and send_clicked().

GtkWidget* textName

Definition at line 68 of file Client.c.

Referenced by createButton_clicked(), LoginPage(), newUser(), and subButton_clicked().

char type[100]

Definition at line 35 of file Client.c.

Referenced by createButton_clicked().

GtkWidget* window

Definition at line 66 of file Client.c.

Referenced by LoginPage(), newUser(), and subButton_clicked().

GtkWidget* window10

Definition at line 80 of file Client.c.

GtkWidget* window2

Definition at line 67 of file Client.c.

Referenced by createButton_clicked(), and newUser().

GtkWidget* window3

Definition at line 75 of file Client.c.

Referenced by mainPage().

GtkWidget* window4

Definition at line 64 of file Client.c.

Referenced by chat_Page().

GtkWidget* window5

Definition at line 63 of file Client.c.

GtkWidget* windowNewPhoto

Definition at line 56 of file Client.c.

GtkWidget* windowSendPhoto

Definition at line 54 of file Client.c.

Referenced by sendPhoto_clicked(), and sendReq_clicked().

GtkWidget* windowView

Definition at line 79 of file Client.c.


Generated on Wed Apr 7 16:48:16 2010 by  doxygen 1.5.8