Two questions on C...
I created my own chat program: Server listens on a main fifo. Client starts, creates a client rfifo and registers client rfifo with server by sending data to main fifo. Server awaits user 2 to connect. Another client(user 2) creates another client rfifo and connects and registers it's own rfifo with server via main fifo. Server sees two users in chat. Server switches client rfifos so that when one user sends data to main fifo, the main fifo returns the data to the other client rfifo. Both users need to be in the same group(prevents the need for OTHER permissions) and all fifos are created in /tmp directory. Chat session takes place over terminal emulator.
1. I'd like to upgrade my chat program by implementing TCP sockets so that the users can access the server remotely. Basically, I'm looking for something to where the server can bind to a tcp port, or even bind a fifo to a tcp socket. Then the client connects to the server via tcp and then would be able to create a client rfifo in the /tmp directory as well as open the main fifo for write. I've done some research and I'm thinking it's rather difficult to implement in this particular way. I don't want to use SSH/Expect or NFS. I don't want to be transferring files to and from server. Is there a library or function that would be able to aid in this way? Where I'd connect to the server and be able to open/create a file in just /tmp directory on the server? 2. On this chat program, it does contain one ugly design flaw. It's designed for just 2 chat users. Basically for one user, it prints its prompt with the username and then the user types in whatever he likes. If the other user types something in and hits enter, the other user's prompt along with the text appears on the users interface. However, if just one user does all the talking, you see an ugly design unfold. Here's an example. Code:
bob: hey |
ok, i gather what you want to create is something like this
+---------------------------+ | | | Chat Log Output | +---------------------------+ | User Input | +---------------------------+ so how do you create that on a terminal. I know of one way which would to a point but there is a slight problem with it. The idea is you a buffered file to standard output. When you flush the buffer, you will be able to recreate the view, scroll the output and do the prompt however the issue is in order for it to be effective you have to know how big the screen is in terms of lines and characters and that is different depending on the terminal. The other thing to do may well be to look at the source code of projects which already do what your after and see if you can understand them. the one i can think of is vim. Or to concede that what your trying to do is too difficult approach and take a different strategy, using ncurses or a GUI toolkit. For the TCP/IP bit, sockets aren't that hard, what you have to think about is TCP or UDP and come up with a way the server or client can communicate effectively. basically your server or client is going to send a message to the other possibly with some data attached, you need to think about what those messages need to be, for example USER <userid> and DATA could be two messages you use, how the client/server will deal with them and what response it needs to send back to the other if any |
Just a different point of view...
Quote:
regards, Heraton |
Thanks pgpython, yea might just go ahead and do ncurses.
Yes Heraton, I just wanted to see if it was possible so that I didn't have to rewrite my whole program. But it's for the best plus I get more experience in server/client using tcp sockets. Thanks guys. |
All times are GMT -5. The time now is 05:06 PM. |