🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

how do you test on 1 machine?

Started by
13 comments, last by Thrump 22 years, 8 months ago
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).
Advertisement
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
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
------------------------------
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
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.
What language are you doing this in?
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.
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
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
"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.
Widelands - laid back, free software strategy
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
------------------------------
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
Oh sorry, you''re right.

cu,
Prefect

One line of sourcecode says more than a thousand words.
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement