I found this website:
http://www.dyndns.com
I started a local server:
` Cube World Server
` This demonstrates how to set up a simple server
` that uses UDP and TCP to relay data to clients
` Operations, used to identify the purpose of each packet
` TCP
#constant OP_NEWPLAYER 0
#constant OP_LEFTPLAYER 1
` Set the local port of the server, this is the port
` that the server will use for both TCP and UDP
LocalPort = 6789
` Set the local IP of the server, this is the local IP
` that the server will use for both TCP and UDP
LocalIP$ = ""
` Set the maximum number of clients that can be
` connected at any one time
MaxClients = 50
` Set the UDP mode which decides how UDP packets
` are dealt with
UDPMode = 1
` Set the number of threads that will be created
` to deal with incoming data. In most cases this
` should be set to the number of processors on your
` computer. MikeNet can determine this for you
` automatically if you set it to 0
NoThreads = 0
` Set the number of MikeNet instances to create
NoInstances = 1
` Setup packets
SendPacket = mn create packet()
RecvPacket = mn create packet()
mn set memory size SendPacket,1024
` Start MikeNet
mn Start NoInstances,NoThreads
` Set the local IP and port of the server
` Note: if we did not use this command then MikeNet
` would find a local IP and port to use automatically
`print localIP$
`LocalIP$ = mn dns("MYDNS")
`LocalPort = 80
profile = mn Create Instance Profile()
mn Set Profile Local profile,LocalIP$,LocalPort,localIP$,LocalPort
mn Set Profile Mode UDP profile,UDPMode
` Attempt to start the server
Result = mn Start Server(0, MaxClients,profile)
` If started successfully
if Result = 0
print "Server started"
print
print "Server local TCP port: "
print mn Get Local Port TCP(0)
print "Server local UDP port: "
print mn Get Local Port UDP(0)
` If failed to start
else
print "Server failed to start"
Wait Key
end
endif
` Main loop
do
` Check to see if a new client has joined
Joined = mn Client Joined(0)
` If a new client has joined
if Joined > 0
` Display client information
print "A new client has joined with a client ID of ";
print Joined
print " Client TCP IP is: ";
print mn Get Client IP TCP(0, Joined)
print " Client TCP port is: ";
print mn Get Client Port TCP(0, Joined)
print " Client UDP IP is: ";
print mn Get Client IP UDP(0, Joined)
print " Client UDP port is: ";
print mn Get Client Port UDP(0, Joined)
` Tell the new client what clients are currently connected
Client as integer
for Client = 1 to MaxClients
if mn Client Connected(0, Client) = 1
if Client <> Joined
mn Add Int SendPacket,OP_NEWPLAYER
mn Add Int SendPacket,Client
mn Send TCP 0,SendPacket,Joined,0,0
endif
endif
next Client
` Tell clients that a new client has joined
mn Add Int SendPacket, OP_NEWPLAYER
mn Add Int SendPacket, Joined
mn Send All TCP 0,SendPacket,0,0,Joined
endif
` Check to see if any clients have left recently
Left = mn Client Left(0)
` If a client has left recently
if Left > 0
` Print the client id of the client who left
print "Client ";
print str$(Left);
print " has disconnected"
` Tell clients that a client has left
mn Add Int SendPacket,OP_LEFTPLAYER
mn Add Int SendPacket,Left
mn Send All TCP 0,SendPacket,0,0,Left
endif
` Deal with new packets from all clients
for Client = 1 to MaxClients
` Check to see if any new TCP packets have been received
TCPPackets = mn Recv TCP(0,RecvPacket,Client)
` If any have been received then do nothing
` since we don't want TCP packets from clients
if TCPPackets > 0
endif
` Check to see if any new UDP packets have been received
UDPPackets = mn Recv UDP(0,RecvPacket,Client,0)
` If any have been received
if UDPPackets > 0
` Get data from packet
PosX# = mn Get Float(RecvPacket)
PosY# = mn Get Float(RecvPacket)
PosZ# = mn Get Float(RecvPacket)
RotX# = mn Get Float(RecvPacket)
RotY# = mn Get Float(RecvPacket)
RotZ# = mn Get Float(RecvPacket)
` Relay data to clients
` Formulate packet
mn Add SizeT SendPacket,Client
mn Add Float SendPacket,PosX#
mn Add Float SendPacket,PosY#
mn Add Float SendPacket,PosZ#
mn Add Float SendPacket,RotX#
mn Add Float SendPacket,RotY#
mn Add Float SendPacket,RotZ#
` Send packet to all clients
mn Send All UDP 0,SendPacket,0,0,0
endif
next Client
loop
mn delete packet SendPacket
mn delete packet RecvPacket
mn delete instance profile profile
mn finish 0
I started the client:
` Cube World Client
` This demonstrates how to set up a simple client
` that uses UDP and TCP to communicate with the server
` Operations, used to identify the purpose of each packet
` TCP
#constant OP_NEWPLAYER 0
#constant OP_LEFTPLAYER 1
` Variables
` Set velocity and turn speed for player movement
Velocity = 5
TurnSpeed = 5
` To be filled during connection
MaximumClients as integer
` Main code
` Set UDP and TCP port of the server, which is 6789
ConnectPort = 6789
` Set timeout value which is the length of time
` in seconds that the command will wait for the
` connection to complete until giving up
Timeout = 4000
` Set the number of threads that will be created
` to deal with incoming data. In most cases this
` should be set to the number of processors on your
` computer. MikeNet can determine this for you
` automatically if you set it to 0
NoThreads = 0
` Set the number of MikeNet instances to create
NoInstances = 1
` Setup packets
SendPacket = mn create packet()
RecvPacket = mn create packet()
mn set memory size SendPacket,1024
` Start MikeNet
mn Start NoInstances,NoThreads
` Get IP address to connect to via UDP and TCP
ConnectIP$ as string
ConnectIP$ = mn dns("MYDNS")
`Input "Enter the IP that you would like to connect to: ", ConnectIP$
`ConnectIP$ = "infonet.dyndns-server.com"
` Try to connect
profile = mn Create Instance Profile()
Connect = mn Connect(0,ConnectIP$,ConnectPort,ConnectIP$,ConnectPort,Timeout, 1, profile)
CLS
select Connect
` If the connection was successful
case 1:
print "Connection was successful!"
` Find maximum number of clients
` necassary for UDP receiving
MaximumClients = mn Get Max Clients(0)
` Display information
Print " The local TCP IP is: ";
print mn Get Local IP TCP(0)
Print " The local TCP port is: ";
print mn Get Local Port TCP(0)
Print " The local UDP IP is: ";
print mn Get Local IP UDP(0)
Print " The local UDP port is: ";
print mn Get Local Port UDP(0)
Print " Your client ID is: ";
print mn Get Client ID(0)
print
print "Press any key to continue"
Wait Key
endcase
` If the connection timed out
case 0:
CLS
Print "Connection timed out. The server may not be available."
Print "Press any key to exit"
Wait Key
end
endcase
` If an unknown error occurred during connection
case -1:
CLS
Print "An unknown error occurred whilst trying to connect."
Print "Press any key to exit"
Wait Key
end
endcase
` If we failed to connect because the server is full
case -2:
CLS
print "The connection request was rejected because the server is full."
print "Press any key to exit"
Wait Key
end
endcase
endselect
` Setup the world for us to run around in
Sync On
Sync Rate 40
AutoCam Off
Make Matrix 1,5000,5000,50,50
Position Matrix 1,Camera Position X(),Camera Position Y()-20,Camera Position Z()
` Once connected, we loop until we become disconnected
while mn Client Connected(0,0) = 1
` Refresh screen
Sync
` Player movement
if UpKey() = 1 then Move Camera Velocity
if DownKey() = 1 then Move Camera -Velocity
if LeftKey() = 1 then Turn Camera Left TurnSpeed
if RightKey() = 1 then Turn Camera Right TurnSpeed
` Deal with new messages from the server
` Check for new TCP messages
TCPPackets = mn Recv TCP(0,RecvPacket,NULL)
` If there is a new TCP message
if TCPPackets > 0
` Get operation of new message
` and player that it applies to
Operation = mn Get Int(RecvPacket)
Player = mn Get Int(RecvPacket)
` If the server is telling us that a new player has joined
` then create a cube for that player
if Operation = OP_NEWPLAYER
if Object Exist(Player) = 0
Make Object Cube Player,50
endif
endif
` If the server is telling us that a player has left then
` delete the cube of that player
if Operation = OP_LEFTPLAYER
if Object Exist(Player) = 1
Delete Object Player
endif
endif
endif
` Check for new UDP messages on a per client basis
` Check each client
PlayerA as integer
for PlayerA = 1 to MaximumClients
` Check for new UDP messages
UDPPackets = mn Recv UDP(0,RecvPacket,PlayerA,0)
if Object Exist(PlayerA) = 1
` If there is a new UDP message
if UDPPackets = 1
` Get the player's position and angle
` and apply them to his/her cube
PosX# = mn Get Float(RecvPacket)
PosY# = mn Get Float(RecvPacket)
PosZ# = mn Get Float(RecvPacket)
RotX# = mn Get Float(RecvPacket)
RotY# = mn Get Float(RecvPacket)
RotZ# = mn Get Float(RecvPacket)
Position Object PlayerA,PosX#,PosY#,PosZ#
Rotate Object PlayerA,RotX#,RotY#,RotZ#
endif
endif
next PlayerA
` Send our position/angle to the server via UDP
` Formulate packet
mn Add Float SendPacket,Camera Position X()
mn Add Float SendPacket,Camera Position Y()
mn Add Float SendPacket,Camera Position Z()
mn Add Float SendPacket,Camera Angle X()
mn Add Float SendPacket,Camera Angle Y()
mn Add Float SendPacket,Camera Angle Z()
` Send packet
mn Send UDP 0,SendPacket,0,0,1
endwhile
` If we have become disconnected from the server
while ScanCode() <> 0
Wait 1
endwhile
while ScanCode() = 0
Text 0,0,"Lost connection to server, press any key to exit"
Sync
endwhile
` Exit
end
I am using
to get the IP address and it work fine. The client just doesn't connect to the Server.
I think this is because it is a local server. I tried:
LocalIP$ = mn dns("MYDNS")
and it didn't work either. I can't figure out which port to use that DYN-DNS uses.
I can't figure out how to get the server setup.
KISTech suggested port forwarding. I don't know how that works. I have my external IP address. Do you just bind that IP address to a port?
Any ideas?
Thanks,
DigitalFury