nie_wiadomo
February 6th, 2008, 02:28 PM
Dear programmers,
I wanted to have a simple messenger for me to talk with my friend. If I wanted to use IM clients, I would be a member of bigger or smaller group of people communicating this way. I thought I needed something more original. Let me state that I'm not a programmer at all and I would just like to finish this application, not necessarily raise my skills to a new level.
Here's my code:
#include <iostream>
#include <fstream>
#include "cstdlib"
#include <string>
#include <vector>
#include "windows.h" //this one is for Sleep, used in other functions
using namespace std;
// some other functions (like checking, if the other side is already trying to update the file) go here
int main() {
std::system("del log.dvc"); // delete the files, wget tends not to overwrite
std::system("del stat"); // anyone knowing how to avoid deleting please let me know
string a;
vector<string> s;
string sl;
//something really unimportant goes here
std::system("cls");
std::system("C:/kontakt/wget/wget.exe --quiet --tries=0 --retry-connrefused --wait=3 http://localhost/log.dvc"); //download the log
ifstream in("log.dvc"); // open log for reading
while(in >> sl) // catch words into a vector
s.push_back(sl);
for(int i = 0; i< s.size(); i++) // display the words inside vector
cout << s[i] << endl; // (log file)
while(1) { // here's where problems begin to appear (Help here please)
std::system("C:/kontakt/wget/wget.exe --quiet --tries=0 --timestamping --retry-connrefused --wait=3 http://localhost/log.dvc"); //keep the log file updated
string sl2;
vector<string> s2; // same as with first log file, catch words into a vector
ifstream in("log.dvc");
while(in >> sl2)
s2.push_back(sl2);
if (s.size() != s2.size()) { // if the just-downloaded log file is different than the one printed out
std::system("cls"); // clear the screen
for(int i = 0; i< s2.size(); i++) // and print the new one
cout << s2[i] << endl;}} // now I have my screen updated, but I'd also like my program to catch the messages written from now on on my computer
return 0;
}
The whole problem lies in what is missing by the last line of while(1). I want my program to update the screen with new messages from the other side while still waiting for me to enter mine. Unfortunately, if I tell it to cin or getchar it will wait for me to click enter before updating log file again, and this is fatal for my messenger (this way it would only check log for new messages after me sending a message). My program uses wput and wget (binaries from sourceforge). The final version would connect to a remote ftp server, I just setup a simple one on my computer for quick tests.
Thanks a bunch for any tips, good luck with interpreting my terrible code.
Michal
I wanted to have a simple messenger for me to talk with my friend. If I wanted to use IM clients, I would be a member of bigger or smaller group of people communicating this way. I thought I needed something more original. Let me state that I'm not a programmer at all and I would just like to finish this application, not necessarily raise my skills to a new level.
Here's my code:
#include <iostream>
#include <fstream>
#include "cstdlib"
#include <string>
#include <vector>
#include "windows.h" //this one is for Sleep, used in other functions
using namespace std;
// some other functions (like checking, if the other side is already trying to update the file) go here
int main() {
std::system("del log.dvc"); // delete the files, wget tends not to overwrite
std::system("del stat"); // anyone knowing how to avoid deleting please let me know
string a;
vector<string> s;
string sl;
//something really unimportant goes here
std::system("cls");
std::system("C:/kontakt/wget/wget.exe --quiet --tries=0 --retry-connrefused --wait=3 http://localhost/log.dvc"); //download the log
ifstream in("log.dvc"); // open log for reading
while(in >> sl) // catch words into a vector
s.push_back(sl);
for(int i = 0; i< s.size(); i++) // display the words inside vector
cout << s[i] << endl; // (log file)
while(1) { // here's where problems begin to appear (Help here please)
std::system("C:/kontakt/wget/wget.exe --quiet --tries=0 --timestamping --retry-connrefused --wait=3 http://localhost/log.dvc"); //keep the log file updated
string sl2;
vector<string> s2; // same as with first log file, catch words into a vector
ifstream in("log.dvc");
while(in >> sl2)
s2.push_back(sl2);
if (s.size() != s2.size()) { // if the just-downloaded log file is different than the one printed out
std::system("cls"); // clear the screen
for(int i = 0; i< s2.size(); i++) // and print the new one
cout << s2[i] << endl;}} // now I have my screen updated, but I'd also like my program to catch the messages written from now on on my computer
return 0;
}
The whole problem lies in what is missing by the last line of while(1). I want my program to update the screen with new messages from the other side while still waiting for me to enter mine. Unfortunately, if I tell it to cin or getchar it will wait for me to click enter before updating log file again, and this is fatal for my messenger (this way it would only check log for new messages after me sending a message). My program uses wput and wget (binaries from sourceforge). The final version would connect to a remote ftp server, I just setup a simple one on my computer for quick tests.
Thanks a bunch for any tips, good luck with interpreting my terrible code.
Michal