Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 CHAT PROGRAM -- Problems with multi-users
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Magnadamus




PostPosted: Thu Aug 11, 2005 10:07 pm   Post subject: CHAT PROGRAM -- Problems with multi-users

I've been working on a chat program today. Simple, just learning the NET commands really. But I'm wondering how/if it is possible to have multiple users connect to the server. It works with one person fine, but how can I make it so I can have 2, 3, 4+ users?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Aug 12, 2005 12:28 am   Post subject: (No subject)

You've got to connect to different ports
Magnadamus




PostPosted: Fri Aug 12, 2005 12:59 am   Post subject: (No subject)

So each client has to connect to the server using a different port? Can the two clients talk to each other through the server?
Tony




PostPosted: Fri Aug 12, 2005 2:04 am   Post subject: (No subject)

indeed.

What you want to do is to relay (as in IRC) the message recieved to all the users connected to the server.

There are some tricks to getting users to connect to the server on different ports. You can start out with hardcoded values for testing purposes (knowing that it will work). Later the server could have a dedicated port to which the user connects.. at that point the server lets the user know of the next available port and disconnects the user, letting another one connect to the same known (and now free again) port. The first user then redials to the recieved port number, trusting the server to be available. (you should not have any problems if you don't have many clients connecting simuntaniusly)
Magnadamus




PostPosted: Fri Aug 12, 2005 2:19 am   Post subject: (No subject)

Alright, thanks... I'm not sure how I'm going to do this but I should be able to figure it out. What will happen later on though, if I have a lot of connections?
Tony




PostPosted: Fri Aug 12, 2005 6:05 pm   Post subject: (No subject)

Don't worry about that for now.
TokenHerbz




PostPosted: Sat Aug 20, 2005 5:19 pm   Post subject: (No subject)

can you just *connect* to the internet??

or do you need to purchase a server to use?

How does that work, can u make a chat that works free?
[Gandalf]




PostPosted: Sat Aug 20, 2005 5:54 pm   Post subject: (No subject)

You can't just *connect* to the internet, because you are connecting to nowhere. The internet is millions of computer, servers, and other things all joined together.

You can either buy (or just use a free) server, or you can just connect the two computers directly. That's the whole thing of an ip (internet protocol) address, each computer connected to the internet has one (therefore you can connect to each computer connected to the internet).
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Sun Aug 21, 2005 5:32 pm   Post subject: (No subject)

ok, can you explain to me about ports?
[Gandalf]




PostPosted: Sun Aug 21, 2005 6:14 pm   Post subject: (No subject)

Quote:
Definition: A port number represents an endpoint or "channel" for network communications. Port numbers allow different applications on the same computer to utilize network resources without interfering with each other.

Port numbers most commonly appear in network programming, particularly socket programming. Sometimes, though, port numbers are made visible to the casual user. For example, some Web sites a person visits on the Internet use a URL like the following:

http://www.somesite.com:8080/

In this example, the number 8080 refers to the port number used by the Web browser to connect to the Web server. Normally, a Web site uses port number 80 and this number need not be included with the URL (although it can be).

In IP networking, port numbers can theoretically range from 0 to 65535. Most popular network applications, though, use port numbers at the low end of the range (such as 80 for HTTP). The port number is included as a field within the header of each IP packet.
Tom West




PostPosted: Tue Aug 23, 2005 9:06 pm   Post subject: Ports

If you want to connect multiple users, you are going to have to learn concurrent programming. It's not much fun, but essentially your server will have one process that is continually listening at a port. Note, that there isn't any need to use more than one port.

Look under process for information on concurrency.

However, the previous poster is right. Get it working for one user (you can use the chat program provided as a Turing example for starters) and understand it well.

Then learn about processes to add multiple users. It's definitely non-trivial.
Token




PostPosted: Wed Aug 31, 2005 11:10 pm   Post subject: (No subject)

just in case your question hasnt yet been answered, you should have the main computer set as the server, most likely yours. and have that computer connect to your first client through a set port, we'll say for example 80, once it connects to the host/server. the server sends back the number of the next open port to connect to, say 81 for example, then client 1 disconnects and reconnects on port 81, client 2 connects on port 80, gets the next open port number, and connects on it. every time somone sends a message, it is sent to the server and then the server echoes it off to all the other clients. hope this helps, if you have any questions i'd be happy to help, or even work on some basic code.
[Gandalf]




PostPosted: Thu Sep 01, 2005 11:56 am   Post subject: Re: Ports

Tony wrote:
There are some tricks to getting users to connect to the server on different ports. You can start out with hardcoded values for testing purposes (knowing that it will work). Later the server could have a dedicated port to which the user connects.. at that point the server lets the user know of the next available port and disconnects the user, letting another one connect to the same known (and now free again) port. The first user then redials to the recieved port number, trusting the server to be available. (you should not have any problems if you don't have many clients connecting simuntaniusly)


Tom West wrote:
essentially your server will have one process that is continually listening at a port. Note, that there isn't any need to use more than one port.


I think those answer the question. No need to revive a topic if one of the above posts is very similar to your own Confused.
Token




PostPosted: Thu Sep 01, 2005 12:03 pm   Post subject: (No subject)

oops, i missed that post, i've been out of the forums for a month or so so i was just trying to get back into it before school starts
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: