LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-05-2011, 10:27 PM   #1
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Rep: Reputation: 70
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
alice:
bob: i was there the other day
alice:
bob: i went and picked up two bottles
alice:
bob: paid 6 bux
So I'd like to have a separate framebuffers, one for the output and another for the input, like all modern chats. Any libs/functions I can take a look at that could help accomplish this? Later on I would like to use ncurses but for now just want to use basic terminal emulator.

Last edited by trist007; 06-05-2011 at 10:30 PM.
 
Old 06-06-2011, 05:26 AM   #2
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

Rep: Reputation: 32
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
 
Old 06-06-2011, 01:39 PM   #3
Heraton
Member
 
Registered: Apr 2011
Location: Germany
Distribution: Mint 10, openSuSE
Posts: 58

Rep: Reputation: 3
Just a different point of view...

Quote:
Originally Posted by trist007
Where I'd connect to the server and be able to open/create a file in just /tmp directory on the server?
I think you don't really need to solve this problem. The chance i see is, that on both machines are programs of you in execution. Any file manipulation can be made from the machine the file is hosted on. The client connects, the server application is opening the file needed. This way, all you have to take care of is transmitting the chat via tcp.

regards, Heraton
 
Old 06-06-2011, 07:19 PM   #4
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,052

Original Poster
Rep: Reputation: 70
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Make questions and ARCH questions for gentoo/calculate linus72 Calculate 5 04-09-2010 12:53 AM
basic questions on hostname and domain name + related postfix questions Moebius Linux - Newbie 7 09-04-2007 11:50 AM
LXer: Questions Answered, Questions Posed - What Happened? LXer Syndicated Linux News 0 05-14-2007 02:46 PM
Solaris - Questions! Questions! Questions! qs_tahmeed Solaris / OpenSolaris 2 07-16-2005 05:27 AM
window manager questions and/or theme questions t3gah Linux - Software 2 02-27-2005 04:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration