Why not work???

BlitzMax Forums/BlitzMax Programming/Why not work???

Zenn Lee(Posted 2007) [#1]
Hi, here is a really simple test TCP network program I
wrote. It works between a LAN but not over the internet, why
not? Please help!!!

Sorry the code is pretty messy:)

SERVER------------------------------------------------------
Framework Pub.TNet_Basic

TNet_HostTCP(22233)
Print "Your IP: "+TNetHost.String_IP

While Not KeyDown( Key_Escape )
TNet_Update()
Wend

CLIENT------------------------------------------------------
'SET GRAPHICS
Graphics 300,200,0

DrawText "Connecting...",100,100
'JOIN GAME
TNet_JoinTCP( "192.168.xxx.xxx" , 22233 )
SeedRnd MilliSecs()
Cls
DrawText "Connection Successful!",100,100
'GLOBALS
Global LocalX%,LocalY%
Global LocalName% = Rand(1,1000)

Global GlobalX,GlobalY,GlobalLive

'MAIN GAME LOOP
While Not KeyDown(Key_Escape)
TNet_DrawClientList()
TNet_Update()
MoveLocalChar()
DrawLocalChar()
GlobalCharDraw()
SendDataLocalChar()
Flip
Cls
Wend

'FUNCTIIONS
Function MoveLocalChar()
If KeyDown(KEY_UP) LocalY=LocalY-1
If KeyDown(KEY_DOWN) LocalY=LocalY+1
If KeyDown(KEY_RIGHT) LocalX=LocalX+1
If KeyDown(KEY_LEFT) LocalX=LocalX-1
End Function

Function DrawLocalChar()
DrawRect LocalX,LocalY,32,32
End Function

Function SendDataLocalChar()
TNet_SendTCP(5,","+LocalName+","+LocalX+","+LocalY+",")
End Function

Function GlobalCharDraw()
If TNet_Receive(5)
Data2$ = TNetData
loc_001 = Instr(Data2$,",")
loc_002 = Instr(Data2$,",",loc_001 + 1)
loc_003 = Instr(Data2$,",",loc_002 + 1)
loc_004 = Instr(Data2$,",",loc_003 + 1)
If Int(Mid(Data2$,loc_001 + 1,loc_002 - loc_001 - 1)) = LocalName
Else
GlobalY = Int(Mid(Data2$,loc_003 + 1,loc_004 - loc_003 - 1))
GlobalX = Int(Mid(Data2$,loc_002 + 1,loc_003 - loc_002 - 1))
End If
End If
DrawRect GlobalX,GlobalY,32,32
End Function


bradford6(Posted 2007) [#2]
most people have 2 IP adresses. a 'public' internet address (the Service provider-provided one) and a local LAN 'private' IP. the '192.168.x.x' address space is private. for use on LANS.

private address (192.168.x.x) is Translated by your router to a public address (62.3.5.x:12345-for example) . the :12345 represents the 'port'

if you want to connect over the internet, you need to know the destination 'public' IP address of your target.

hope that helps


Zenn Lee(Posted 2007) [#3]
Oh thanks so much Bill! This really, really, helps! You don't know how much time I spent messing around with this, trying to get it to work.

Thanks


bradford6(Posted 2007) [#4]
no problem, try this:
http://www.showmyip.com/


Zenn Lee(Posted 2007) [#5]
OK, so it would be 68.60.xxx.xxx?
(I doesn't seem to work when I try to connect, hu?)
I'll let the server run, could you try and connect using
68.60.104.172. I'll leave it on for a few minutes)

Also, when I use TNetHost.String_IP it finds 192.168.0.100 not 68.60.xxx.xxx?


Zenn Lee(Posted 2007) [#6]
TNet_JoinTCP(68.60.xxx.xxx,22233)
So like this^


bradford6(Posted 2007) [#7]
Here is how it works:

your router has a pool of addresses(DHCP) or a static IP Address that is assigned to your PC.

192.168.0.100 <PC>----<router> 68.60.xxx.xxx-----<<The Internets>>----OtherPC-Public IP <router>----<PC> OtherPC-Private IP


bradford6(Posted 2007) [#8]
sorry, i do not have TNET installed in my system. I can't ping 68.60.104.172 though. are you sure that is your public IP (it might just be that echo response is off so ping does not work...or firewall is preventing it)
anyway. good luck with this. It is past my bedtime...


Czar Flavius(Posted 2007) [#9]
I wouldn't go posting your IP around like that.


Zenn Lee(Posted 2007) [#10]
"I wouldn't go posting your IP around like that."
Ha, you are right:)

Thanks a lot guys just wish I could get this thing working!
Wave is a cool guy and TNet is great, just wish he had more tutorials!!!


Gabriel(Posted 2007) [#11]
If you're going through a router, you will need to configure your router to forward whatever port you're using.


bradford6(Posted 2007) [#12]
Gabriel, true. http://portforward.com/routers.htm

Zenn,
TNET is no longer being dev'd. why not use GNET?


Zenn Lee(Posted 2007) [#13]
Might be a good idea, I'll look into it. Is it as simple for high level stuff as TNet? Oh ya, is there any tutorials?


bradford6(Posted 2007) [#14]
honestly, I have never really used GNET. but I will give it a whirl tonight...