im trying to create a simple LAN Chat Program (as projectwork for school)....usage of filehandling is a must in all projects...since all the school computers are connected by LAN...i am creating one FILE and trying to input and read that file and display it on the screen to make it LIKE a chat room.(see the program below).
#include<all.h>
void main()
{
clrscr();
ofstream fout;
char uname[21],t[101],u[101];
fout.open("Chat.txt");
fout<<"Connecting...\nConnection Established\nWELCOME TO THE C++ CHAT ROOM\nRules:\nType \'exit\' to go out of the chat room.\n\n";
fout.close();
cout<<"Enter username : ";
gets(uname);
strcpy(u,uname);
ifstream fin;
start:
clrscr();
fin.open("Chat.txt");
while(fin.eof()==0)
{
fin.getline(t,101);
cout<<t<<endl;
}
fin.close();
fout.open("Chat.txt",ios::app);
cout<<uname<<" : ";
gets(t);
if(strcmpi(t,"exit")==0)
{
cout<<"\nPress any key...";
getch();
exit(0);
}
strcat(u," : ");
strcat(u,t);
fout<<u<<endl;
strcpy(u,uname);
fout.close();
delay(500);
goto start;
getch();
}
Two users can simultaneously run the program on two diff computers .so what one types gets stored in the file - "chat.txt"(shared documets-accessible by both the comps)...THE PROBLEM IS...user1 types a msg it stores in chat.txt ....which is not immediately displayed in user2's window but only after user2 enters the message he is to be sending (gets(t)) .after entering it goes to label 'start' and freshly opens the file again for reading....that is...user2 is able to view the msg that user1 typed only after he types the message.
is there any way how the msg a user types gets recieved immediately even though the reciever does not enter a msg.
NOTE: THIS CAN BE TESETED IN A SINGLE COMPUTER BY OPENING TWO WINDOWS OF THE exe FILE CREATED BY C++ and exchanging msgs.( im using Turbo C++).
waiting for help and comments