Archived

This topic is now archived and is closed to further replies.

Thrump

how do you test on 1 machine?

Recommended Posts

Thrump    169
I''m trying to make a multi-chat program. I''m wondering if there''s a good way to test it out on 1 machine. If you have 2 server sockets listening on the same port, how do send a message to 1 but not the other? Also, if anybody has a good online reference for what I''m trying to do, that would be great. (not simple 1 on 1 chat programs).

Share this post


Link to post
Share on other sites
ncsu121978    1344
you cannot have two server listen sockets on the same machine that listen on the same port. It should return an error to you when you try to bind the second listen port to the port that is already being used. You can have two server listen sockets on the same machine, they just have to use different ports.

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share this post


Link to post
Share on other sites
griffenjam    193
Your server listening socket should never remain in use.
When you get an incoming connection you hand it off to another socket and leaving the server socket open (I think this is done automatically). So there is no reason you want to listen on the same port twice, if you''re testing Server-to-Server communications just change the listening port on server 2 while your testing it.

About 2 years ago I wrote a simple chat program that supported 5 people in a chat at once, I think that''s what your looking for.
I lost the source, but lately I''ve been remaking my winsock engine. If you want I will rewrite this program (when I have some time) and send it to you.

Also a really good resource can be found at
http://tangentsoft.net/wskfaq/
That is the FAQ for a Winsock newsgroup.

Jason Mickela
ICQ : 873518
E-Mail: jmickela@pacbell.net
------------------------------
"Evil attacks from all sides
but the greatest evil attacks
from within." Me
------------------------------

Share this post


Link to post
Share on other sites
Thrump    169
Griffenjam, a 5 way chat is exactly what I need, but I don''t expect you to go and write it for me . I''m very new to sockets, and I''m having a bit of trouble wrapping my head around things, so a simple explaination of how you did it would be great. Does one person act as a server that everybody connects to? That FAQ looks good. Lots of stuff to read over tonight. Thx for the help.

Share this post


Link to post
Share on other sites
Thrump    169
I''m doing it in Delphi. Actually, I just found a socket component for it, and it has an example of a multi-chat program. Yeah, I know it''s cheating, but there''s lots more I want to do.

Share this post


Link to post
Share on other sites
Dire.Wolf    122
Using examples is not cheating...it is how humans learn the best. Hell I''m always looking at samples because:

a) most programmers have a different perspective than me.
b) different coding techniques (some good, some bad).
c) sometimes the documentation just isn''t as clear as a good example.

If you get stumped, let us know. I''m not a Delphi programmer though - only C/C++, Java, and VB.

Best regards,




Dire Wolf
www.digitalfiends.com

Share this post


Link to post
Share on other sites
Prefect    373
"When you get an incoming connection you hand it off to another socket and leaving the server socket open (I think this is done automatically). So there is no reason you want to listen on the same port twice, if you''re testing Server-to-Server communications just change the listening port on server 2 while your testing it. "

Wrong.

When you do an accept() on a listening socket, a second socket will be created. The first socket will still be listening on the same port, while the second socket will be connected to the peer. Both sockets are bound to the listen port of the listen socket. There is no switching ports involved in this.

When you initiate a connection from an unbound socket, the OS will choose a random port for the connection. So unless you intend to run two servers on the same machine, you''ll never get into trouble.
You still can run two servers at the same time if they use different listen ports.

cu,
Prefect

One line of sourcecode says more than a thousand words.

Share this post


Link to post
Share on other sites
griffenjam    193
Umm....You do realize that your description of the process is almost exactly the same as mine.

The only differance is this line
"if you''re testing Server-to-Server communications just change the listening port on server 2 while your testing it"

Which in not wrong, if you write a chat program that uses more than one server that runs on 2 machines, but the servers need to talk to each other, then you would have to change the listening port on one of the servers because they will both be listening for a connection on the same port.





Jason Mickela
ICQ : 873518
E-Mail: jmickela@pacbell.net
------------------------------
"Evil attacks from all sides
but the greatest evil attacks
from within." Me
------------------------------

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Thrump
I''m doing it in Delphi. Actually, I just found a socket component for it, and it has an example of a multi-chat program. Yeah, I know it''s cheating, but there''s lots more I want to do.


Cool :-) im a delphi programmer .. so if you ever need some code checkin or anything just ask!

good luck

~ Tim

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
From what I''ve read it doesn''t sound like you are trying to do server-to-server comms. Just a standard chat server right? If that is true, read on, otherwise ignore this.

I''m not a delphi programmer either, but the process should be relatively similiar as C/C++.

1. Make the socket and set the options you want.
2. Configure the socket to the IP and port you want to use
3. Bind()(or delphi equivalent) it.
4. Listen().

Then, in your main loop you need use some method of polling that socket you just created. I use select() for C/C++. If the server socket polls as active, then you have a new person attempting to connect and you''d call an accept() (C/C++) on it. You need to store the return value somehow of course.

That''s all you really need to set up the server and listen for connections. The rest of the processing is done by polling the stored sockets...

Is this helpful?

= Fleet

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
From what I''ve read it doesn''t sound like you are trying to do server-to-server comms. Just a standard chat server right? If that is true, read on, otherwise ignore this.

I''m not a delphi programmer either, but the process should be relatively similiar as C/C++.

1. Make the socket and set the options you want.
2. Configure the socket to the IP and port you want to use
3. Bind()(or delphi equivalent) it.
4. Listen().

Then, in your main loop you need use some method of polling that socket you just created. I use select() for C/C++. If the server socket polls as active, then you have a new person attempting to connect and you''d call an accept() (C/C++) on it. You need to store the return value somehow of course.

That''s all you really need to set up the server and listen for connections. The rest of the processing is done by polling the stored sockets...

Is this helpful?

= Fleet

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
From what I''ve read it doesn''t sound like you are trying to do server-to-server comms. Just a standard chat server right? If that is true, read on, otherwise ignore this.

I''m not a delphi programmer either, but the process should be relatively similiar as C/C++.

1. Make the socket and set the options you want.
2. Configure the socket to the IP and port you want to use
3. Bind()(or delphi equivalent) it.
4. Listen().

Then, in your main loop you need use some method of polling that socket you just created. I use select() for C/C++. If the server socket polls as active, then you have a new person attempting to connect and you''d call an accept() (C/C++) on it. You need to store the return value somehow of course.

That''s all you really need to set up the server and listen for connections. The rest of the processing is done by polling the stored sockets...

If you assign the IP adx to 127.0.0.1 you can telnet to yourself.

Is this helpful?

= Fleet

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
From what I''ve read it doesn''t sound like you are trying to do server-to-server comms. Just a standard chat server right? If that is true, read on, otherwise ignore this.

I''m not a delphi programmer either, but the process should be relatively similiar as C/C++.

1. Make the socket and set the options you want.
2. Configure the socket to the IP and port you want to use
3. Bind()(or delphi equivalent) it.
4. Listen().

Then, in your main loop you need use some method of polling that socket you just created. I use select() for C/C++. If the server socket polls as active, then you have a new person attempting to connect and you''d call an accept() (C/C++) on it. You need to store the return value somehow of course.

That''s all you really need to set up the server and listen for connections. The rest of the processing is done by polling the stored sockets...

If you set up your IP address to 127.0.0.1 you can telnet into yourself to test it out. Choose any non-reservered port (above 1000 is safe I believe).

Is this helpful?

= Fleet

Share this post


Link to post
Share on other sites