Click here to Skip to main content
15,887,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a simple messenger at first I didn't use fork to contract between host and user and stored users information into a structure so when user asked for them I turned them back to her/him.
but I find host cannot answers to multiple users at the same time without forking and now when I use fork I don't know what is happening so I cannot get back users information to her/him.
it's urgent situation I know using database would solve it but is there any other suggestion please(that was for my university project and deadline is about 5 more hour :( )

What I have tried:

if you interested to see part of the code inform me cause it is too long and don't think be useful
Posted
Updated 1-Jul-18 0:27am

To support multiple users connected at the same time you can create threads that service the connections. That is more leight weighted than forking a whole process and allows access to common and shared data.

Another solution is using a list that holds the connection and user related data.

But these are design decisions that should be done before starting writing code.

In your case using threads might be simpler (faster) to be implemented. But even I as experienced developer would it probably not get done in five hours.
 
Share this answer
 
Comments
Member 13606974 1-Jul-18 5:08am    
I know that it isn't possible in 5 hours :(, but wanted to try it later in holiday, so it is related to database or not?(I don't now even what is database)
Jochen Arndt 1-Jul-18 16:29pm    
Forking and sockets are not related to databases in any way.

It is another design decision how to store your user data. An application for many users will probably use a database for that. But for a few users you might also create a data file per user. Such files may be text based or hold serialised objects.
Quote:
I know that it isn't possible in 5 hours :(, but wanted to try it later in holiday, so it is related to database or not?(I don't now even what is database)

Probably not: the problem is that when you tell your Socket to Listen, it does not return until it has a connection, so to support multiple users you need multiple processes - which means you need to use fork and then respond to the appropriate Socket when it gets a message. A database won't help you with that, it doesn't support multiple Sockets, it just stores data!

You only have three hours left, and to be honest, unless you can get the fork / sockets working in that time how you store the data is irrelevant (not to mention that learning databases isn't a five minute job - heck it'll probably take you longer than that to install a multiuser database system in the first place, never mind learning to use it as well!)

If you can work on it over the holiday, then do: get forking and sockets sorted first and don't worry about data until after that.
 
Share this answer
 
Comments
Member 13606974 8-Jul-18 17:57pm    
currently I started to learn them, thanks
OriginalGriff 9-Jul-18 1:27am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900