I am writing a simple chat-room application in c using posix sockets. However I'll have this issue in sending messages.
(client1)say something: Hello folks! what are
client2 said: xyzabc
client3 said: dsgh
Here above is the client1's terminal window where he was trying to send "Hello folks! what are you doing?" but before he could write his messsage and press enter, client2 and client3 sent something.(separate thread for receiving messages)
I'm trying to tackle this issue by using 2 different terminal windows for each client, one for writing the message and another for displaying the chat messages.
To begin with I've opened a gnome-terminal window by writing
system("gnome-terminal");
but now,
I want to perform some read write operations on the terminal window I've opened and the existing window.
printf("This is existing window"); //want to print this on existing terminal
printf("this is new terminal window"); //want to print this on new terminal
scanf("%d",&a); //take input from existing window
scanf("%d",&b); //take input from new window
I've read here that I can do it by reading/writing from proper /dev/pts/<n>
file.
But how do I find the n in the /dev/pts/<n>
for the current terminal and the new terminal window I just opened? Is there any better way of solving the issue?