i have set up a simple… YES SIMPLE its actualy less that 30 lines total … networking system that works localy. it has no designated server or client, the idea is that the two computers just exchange information. im having trouble geting the message to other computers though. im not sure what is wrong.
ive replaced my actual ip address with a fake one for security. but i am sure i have the right ones typed in.
Well if you want 10 separate connections for some reason then yes.
But for a simple client-server network you wont need more then 1 or 2.
The client needs only one socket and can use it to send to any number of different servers. The same is with the server, you bind only one socket and can use it for any number of clients. You can use 2 sockets on the server if you want to separate the lobby from the game.
The port is singular when thinking about how you can read from it on the local machine, but the data you receive can be from any of the clients. A simple to understand analogy is a mailbox. Even if you only have one, anybody can put something in it. Well, usually only a mailman, but you get the point.
Sorry, let me try to verbalize this better. I am watching the Goran multiplayer tutorial here ( http://www.youtube.com/watch?v=4xZRfzOtxzA ). During the video he has port 9999 to create the socket. However, once the socket is created, I noticed that it’s not on port 9999 but it appeared moreso that port 9999 was a gateway between client socket (which was signed a port number upon socket connection) and server port communication.
Does that make sense? Even though client/server is happening on 9999 (or whatever port is specified), does the Socket create a random/next in line quazi uPnP port to communicate on said socket?
watching the same tutorial (Goaran’s multiplayer one) i wrote this code, also after a close look i realised i got the ip wrong on the client side. so binding on the client side is not nessesary. with this code both computers are acting as clients and servers. as far is i understand it, The important part is that the reciving port must not change. the client must have a designated reciving port and the server must have a desegnated reciving port. 9999 was a convineint free port on both computers. thanks for the reply’s
about the logistics issue. aggose’s page explained it fairly well. there is just a “middle man” with a know ip address for connecting. and the middle man would just send the ip address of the other computer to each client. but i don’t have a computer to designate to connections. and in this case there is no “Server” it seems more efficent to have the clients do their own work right?
@@szupek If you want to use more than one port you can. For instance, you can wait for clients to send you a something on 9999, then you can send them a message back on 9999 which tells them what port to use for the rest of the conversation. This way you can organize your communications with client better. However, none of this is done by the sockets behind your back, it is something you would have to specify yourself.
So, i had an idea on the whole connecting two computers thing.
so far i was only able to connect to computers on a local network. usualy computers on a network have the same first few # in their ip. for one case lest use. 192.168
They also have the same third # lets say .32
then they will have the last # be sequental from a start #. so the last # on a series of computers in a network might be:
.100 .101 .102 .103 .104 .105 .106 ect. for every computer on the network
so… you can “search” for other computers trying to connect on the same network, by having both recive input, while they are both brodcasting their ip to ip’s in sequental order.
so computer 192.168.32.102 would send its IP first to 192.168.32.103 and then to 192.168.32.101 and then .104 ect,
and computer 192.168.32.106 would start by sending to .107 and then to .105. each would continue untill they recieved an IP address or a message that would essentaly say “STOP”.
if they recived an IP address: they would then send “STOP” followed by another message that would contain their IP address, to the ip that they received.
if a computer received “STOP” it would wait to receive the IP address of the computer that stoped them.
Now both computers know which IP to send to!
In this way on a local bassis, in less than a minute, (there are realy only 255 possibilities) the computers could connect if they are on the same network.
What i need you to tell me is wether or not this is actualy the case. do all local ip addresses follow the same pattern?
PS: ive actualy tried it just pinging with the CMD in windows, on a public network. i found 2 or three computers on the network this way.