More (Specific) Help With Online-Ness
Blitz3D Forums/Blitz3D Programming/More (Specific) Help With Online-Ness
| ||
I can't figure out why this isn't working, mostly because I'm so new at online programming. I've got:Graphics 800,600,32,2 Print "Connecting..." tcp=OpenTCPStream( "www.alloidgames.com",80 ) If Not tcp Print "Failed.":WaitKey:End Print "Connected! Sending request..." WriteLine tcp,Chr$(10) If Eof(tcp) Print "Failed.":WaitKey:End Print "Request sent! Waiting for reply..." While Not Eof(tcp) Print ReadLine$( tcp ) Wend Print "Connected!" While Not KeyHit(1) If KeyHit(6) Then AcceptTCPStream(tcp) alk$ = Input("") WriteLine(tcp,alk) Print ReadLine(tcp) End If Wend CloseTCPStream tcp WaitKey End It's supposed to, if you press 5, get input, and then print it back, but the printing part isn't working! What am I missing!? |
| ||
Haven't messed with the networking stuff myself, but just quickly looking at your code, are you allowing the other side enough time to reply? I kind of doubt (but don't know for sure) that ReadLine actually waits for data to be present before it reads it. |
| ||
I think you need to formulate a valid http request. Check out the sample code for ReadAvail(). Not too sure how it works now tbh but I guess the server is not going to waste time replying to any old rubbish :). |
| ||
I added a ReadAvail()and apparently there are 0 availible bytes....also when I tried running the demo it failed. I don't think I understand this online thing at all... |
| ||
Just use the readavail sample code and replace both the references to blitbasement.com with your own site name. Do not change anything else. It works here. Now read this and look at some of the code on the code archives. http://www.comptechdoc.org/independent/web/http/reference/ |
| ||
Looking at the website now, but whenever I run the demo for ReadAvail, I get an error (and 0 avail bytes). When I sub in my stuff, it prints out a bunch of text which looks suspiciously like the html for the website I'm putting in, and every other line it prints out the avail bytes, but at the end, it shows 0 avail. Sorry I'm so n00bish at this, and your help is REALLY appreciated. If I can ever get a good game made thanks to this, I won't forget who helped me get my feet set! |
| ||
That is because blitzbasement.com has long since ceased to exist, so really that sample code should be updated. Anyway what you see when you put your site in is indeed the Html for your site. That is primarily what you will get on port 80 since that port number is reserved for serving html. Other ports may support different protocols or be unassigned. For instance this code archive entry http://www.blitzbasic.com/codearcs/codearcs.php?code=16 uses port 21 since that port is reserved for use by FTP (File transfer protocol). There is a list of commonly used ports here http://www.iana.org/assignments/port-numbers Anyway the readavail() function shows how much data is available on a stream. As your program is likely much faster than your internet connection you can check readavail to see if more data is available and if not get on with something else. If you do not have a dedicated server then you are likely to be limited as to what you can actually do with it and what sofware you can run on it. I am very vague on this and others will be able to advise you better. You can of course use your existing PC and internet connection to provide any sort of service you like, including an in game service, provided you configure your firewall accordingly to open up the required port. The same can be said for any user of your game, they may act as a server or client. Typically the server would advertise the presence of the game online in some sort of lobby. Like the Gnet one hosted on this site: http://www.blitzbasic.com/gnet/gnet_servers.php using this code http://www.blitzbasic.com/toolbox/toolbox.php?tool=61 Never used it myself, but I am sure someone will be able to fill you in on the details of its use. So, what is it that you want to achieve? (Or as Microsoft might put it, "Where do you want to go today?") |
| ||
Well the long term is to have a game, that without going into details, is one-on-one turn based, with live rankings. Short term, just to get the hang of online programming, I'd like to make just a simple chat engine that me and my friend (about 200 miles north of me) can use to talk to each other. |
| ||
alloid, if you get something going regarding your chat engine, I would like to see your blitz code later if you don't mind sharing it, since I too will be embarking on a quest to make an online game/game server. |
| ||
Sure thing! But you're probably better off finding help from someone who knows what they're doing... Also, DJ, don't I need availible bytes to write a line? So how do I get space? And what port would be needed for the basic chat engine? |
| ||
I would presume using one that no one else is using would be a good choice? If you have a firewall though, you will have to explicitly let that port traffic go through. It looks like Internet Relay Chat uses port 194... PrivateChat is 1735? Very simple chatroom prot is 3073 |
| ||
Hrm, well, I'm sure this'll annoy you guys even more, but I only know a tiny bit about ALL online-related-programming-needed things, including port forwarding and firewalls |
| ||
There is an example of a chat program on the archives. http://www.blitzbasic.com/codearcs/codearcs.php?code=28 Have not tried it myself, but let us know if you have any problems. |
| ||
Ah that looks really good! Thanks! |
| ||
This has been INCREDIBLY educational so far, but what do I need to do so that I can run it off/through (not sure what the correct wording is) my server (alloidgames.com). I tried switching the CreateServer to OpenServer in the server code, and pointing the OpenServer on the client code to the same place. However, if I try on port 40000, they don't start up, and if I try it on something like 80, it starts up but doesn't work (and I get to see that lovely html again >_<) |