Simple Networking Problem
Blitz3D Forums/Blitz3D Beginners Area/Simple Networking Problem
| ||
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 |
| ||
I have the same problem :( unfortunatey I never figured it out and gave up on networking but I am picking it up again. |
| ||
At least I'm not alone. Somebody has to have done some networking, right? |
| ||
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 |
| ||
Plenty of people have done network coding, there are many examples in the code archives. |
| ||
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 |
| ||
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 |
| ||
So you want your inner network IP. I think its in the control panel under network something. PS: AJ00200 IP Finder |
| ||
thanks aj00200 ill try it out |
| ||
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 |
| ||
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. |
| ||
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 |
| ||
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) |
| ||
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? |
| ||
if you dont know your ip and uses tcp. "localhost" is the right one :) |