Simple Networking Problem

Blitz3D Forums/Blitz3D Beginners Area/Simple Networking Problem

Whats My Face(Posted 2009) [#1]
Hello I'm trying to create a server and client on my own system but when I run the server and then the client I can only get one piece of data between per time I run the client code.

Server:
AppTitle "Server"

Global svrGame = CreateTCPServer(8080)

While Not KeyHit(1)
	Local stream = AcceptTCPStream(svrGame)
	If stream <> 0 Then 
		Print ReadLine(stream)
	EndIf 
Wend



Client:
AppTitle "Client"

Local strmGame = OpenTCPStream("127.0.0.1",8080) 


While Not KeyHit(1)
	WaitKey()
	WriteLine strmGame,"Hello"
Wend



Nate the Great(Posted 2009) [#2]
I have the same problem :( unfortunatey

I never figured it out and gave up on networking but I am picking it up again.


Whats My Face(Posted 2009) [#3]
At least I'm not alone. Somebody has to have done some networking, right?


Whats My Face(Posted 2009) [#4]
Totally just figured it out.

Replace the old server code with this:
AppTitle "Server"

Type user
	Field id
End Type

Global svrGame = CreateTCPServer(8080)

While Not KeyHit(1)
	Local connect = AcceptTCPStream(svrGame)
	If connect Then 
		u.user = New user
		u\id = connect
		Print "New Connection: " + connect 
	EndIf 
	
	For u.user = Each user
		If ReadAvail(u\id) > 0 Then
			Print ReadLine$(u\id)
		EndIf
	Next
Wend




Matty(Posted 2009) [#5]
Plenty of people have done network coding, there are many examples in the code archives.


Whats My Face(Posted 2009) [#6]
OK new problem but since its for the same general code I'm going to leave it in this thread. How come when I have more than one client for the server and I tell the server to send a packet to the client every second telling it its name the client starts getting empty lines?

Server:
AppTitle "Server"

Type user
	Field id
End Type

Global svrGame = CreateTCPServer(8080)

While Not KeyHit(1)
	Local connect = AcceptTCPStream(svrGame)
	If connect Then 
		u.user = New user
		u\id = connect
		Print "New Connection: " + connect 
	EndIf 
	
	For u.user = Each user
		WriteLine u\id,"Hello Player: " + u\id 
	Next
	Delay 1000
Wend


Client:
AppTitle "Client"

Local strmGame = OpenTCPStream("127.0.0.1",8080) 


While Not KeyHit(1)
	If ReadAvail(strmGame) Then
		Print ReadLine$(strmGame)
	EndIf 
Wend



Nate the Great(Posted 2009) [#7]
hmmm I dont understand the problem you said you are having but another question I have is: What is my IP?!?! and no whatismyipaddress.com doesnt work for networking stuff for some reason


AJ00200(Posted 2009) [#8]
So you want your inner network IP.
I think its in the control panel under network something.
PS: AJ00200 IP Finder


Nate the Great(Posted 2009) [#9]
thanks aj00200

ill try it out


Nate the Great(Posted 2009) [#10]
ok... so I have 3 different numbers

I have what I guess is my local one from the control panel but there are two of them. then I have my ip from your website aj00200

which one do I use to create servers etc? this is so confusing

and sorry for hijacking this thread


AJ00200(Posted 2009) [#11]
OK, the one from my site is if you want a world-wide server. Then you have the client connect to that (make sure to get a static IP from your ISP).

Then you have to enable port forwarding form your games port to your local network IP address (instructions depend on your router/network equipment).

You can connect to your computer via your network from the numbers off the control panel (I don't know which you need to use, I'd need to know what they are titled), and just connect on port 8080 (check your FireWall).

Hope that helps a bit.


Nate the Great(Posted 2009) [#12]
So all I need is to enable port forwarding.. where would I find out about this, I have a 2wire thing and I know what each of my computer's local ip's are


AJ00200(Posted 2009) [#13]
Sorry, I can't figure that out either.
I have the same problem, and can't find a good explanation.

It is somewhere in your routers web-based setup.
try typing this into your browser (192.168.0.1 or 192.168.0.0)


Whats My Face(Posted 2009) [#14]
Nate the Great! You just hijacked my thread! I thought we were friends :)

Anyways if I could redirect the flow of this thread back to my problem. Why are packets being dropped when I use above code with more than one client running on my computer?


Wings(Posted 2009) [#15]
if you dont know your ip and uses tcp. "localhost" is the right one :)