Skip to content

Commit

Permalink
Client code updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhav Agarwal committed Apr 6, 2012
1 parent 5451373 commit dbdece8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 43 deletions.
26 changes: 17 additions & 9 deletions client.c
Expand Up @@ -9,10 +9,14 @@
#include<unistd.h>
#include<errno.h>

int gettingFile ( char * packet )
{
return 1;
}

int main(int argc, char** argv)
{
FILE *fp;
fp = fopen("output.html", "w");
int clientSockID, bytes_recieved, sentBytes;
char packet[1024];
char *file_path, recvData[1024];
Expand All @@ -21,6 +25,7 @@ int main(int argc, char** argv)
struct timeval timeout;
host = gethostbyname((char *)argv[2]);

// Not able to connect to the server . Error and exit
if((clientSockID = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("Socket");
Expand All @@ -37,19 +42,18 @@ int main(int argc, char** argv)
exit(1);
}

printf("\nConnection Established : Enter File URL : ");
// gets(file_path);
file_path = argv[3];
printf("%s file_path commandline", file_path);

create_packet("GET",file_path, "", packet);
printf("packet being sent %shello1", packet);
printf("foo bah");
if( (sentBytes = send(clientSockID, packet, strlen(packet), 0)) == -1)
{
perror("sentBytes");
}
int cnt = 0;
int cnt = 0;
char *BASE_URL = "cache/";
char * fileSave = strcat(BASE_URL , file_path );
fp = fopen(fileSave, "w");
while(1)
{
bytes_recieved = recv(clientSockID, recvData, 1024 , 0);
Expand All @@ -62,12 +66,16 @@ int main(int argc, char** argv)
}
else
{
fprintf(fp, recvData);
recvData[bytes_recieved] = '\0';
printf("\nRecieved data = %s " , recvData);
if ( gettingFile( recvData ))
{
fprintf(fp, recvData);
recvData[bytes_recieved] = '\0';
printf("\nRecieved data = %s " , recvData);
}
}
cnt++;
}
fclose(fp);

}

4 changes: 2 additions & 2 deletions makefile
Expand Up @@ -15,5 +15,5 @@ client.o: client.c
Webmaster_client.o: Webmaster_client.c
gcc -g -c $<
clean:
rm *.o
rm server client
rm -f *.o
rm -f server client
27 changes: 0 additions & 27 deletions output.html

This file was deleted.

7 changes: 2 additions & 5 deletions sweb.py
Expand Up @@ -8,8 +8,6 @@

class BrowserWindow:



def __init__(self):
self.root = Tk()
self.root.geometry('%sx%s+0+0'% self.root.maxsize() )
Expand Down Expand Up @@ -37,15 +35,14 @@ def __init__(self):
def displayText(self):
""" Display the Entry text value. """


if self.entryWidget.get().strip() == "":
tkMessageBox.showerror("Tkinter Entry Widget", "Enter URL")
else:
URL = self.entryWidget.get().strip();
os.system("./client 7000 localhost " + URL);
os.system("./client " + sys.argv[1] + " " + sys.argv[2] +" " + URL);
numlines = self.w.index('end - 1 line').split(' . ')[0]
self.w.delete(1.0 , numlines )
self.openPage("output.html")
self.openPage( URL );



Expand Down

0 comments on commit dbdece8

Please sign in to comment.