Okay, I've really been getting into making little C++ and QuickBasic games lately, but I've always wanted to make an online one. How difficult is this? If I have a variable in C++ and know the exact IP address of the other computer, how complicated would it be to send the variable to the other computer?
I've never used any 'standard' c++ networking libs, but you should use sockets for this (there is a standard sockets.h i think, but i've only used em thru python and wxWidgets)

try searching for c++ sockets (or even just C sockets, as C code can be used in C++ just fine)

generally tho, you create a new socket object, call its connect function (this is where you'll have the other comps IP and Port) - it MUST be listening for connections! (socketServer object). Then, once the connection is established, you just call a send(variable) on the client (or server) and a recv(variable) on the server (or client)

sockets are dumb however, so you could send an int (which is 4 bytes usually) and then do a recv with a char (which is 1 byte) and it will have no problems with that - you could actually do 4 char receives, as its just stored byte-for-byte, no header info or anything like that

Sorry I can't give you better info tho, its been awile since I've used sockets in C/C++
Thanks. I had no idea how to even get started. I try to find out programming stuff myself but I had no clue what to even type for a google search.
Wikipedia has gotten mature enough that I find it easier to get information there than Google -- give it a whirl.
Alright, thanks.
Just in case:
http://en.wikipedia.org/wiki/sockets
KermMartian wrote:


* http://en.wikipedia.org/wiki/Berkeley_sockets

Wink (btw, you linked to a page that doesn't exist, lol)
I didn't actually check it; I just typed http://en.wikipedia.org/wiki/topicname
thats kinda what i figured, lol
Now the page exists. Smile
KermMartian wrote:
Now the page exists. Smile


Did you just creat it? Incase you didn't notice, http://en.wikipedia.org/wiki/Socket already exists and covers everything much better Wink
Yeeeeah, realized that after I made the page. Whoops.
Just in case it didn't say in the Wiki article (I didn't check), to use sockets with windows in C++, you need to use winsock.h. You might have to make a server program to handle additional players (depending on the style of online game you're making). I'd try finding a good winsock tutorial to get started. MSDN has their usual technical crap, but it'll really help you understand the function syntaxes.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/windows_sockets_start_page_2.asp

I started working on a socket class awhile back, but never finished it. I should get it done...
Hmmm, this is exactly the kind of stuff I'll/other people will need to know for the gCn programs. Ty, Jincs.
[quote="JincS"]Just in case it didn't say in the Wiki article (I didn't check), to use sockets with windows in C++, you need to use winsock.h.quote]

I believe you can still use the standard socket.h file in windows too, which follows the "standard" berkley socket API, although admittedly I haven't ever done socket programming directly, and instead went through Python or wxWidgets...

KermMartian wrote:
Hmmm, this is exactly the kind of stuff I'll/other people will need to know for the gCn programs. Ty, Jincs.


No, Python has built in socket support. No need to learn the specific quirks of each OS's socket interface
Oh, reallly? Even better! So I guess Python has some advantages over lower-level OOPs.
KermMartian wrote:
Oh, reallly? Even better! So I guess Python has some advantages over lower-level OOPs.


here is a list of the standard, bundled modules http://docs.python.org/modindex.html

As you can see it is quite extensive, even including a GUI API (tkinter), various networking stuff (from low level sockets to one-command opening of a website using urllib), sound, various os and system functions, all sorts of stuff

Python has alot of advantages over lower-level languages, or even against other high level langs like Perl or VB.
/me reads....wow, that is quite impressive. Perhaps I should consider learning Python more thoroughly myself...
Good point Kllrnohj: Berkely Sockets should work with Windows, and I would recommend it (just 'cause I don't like winsock).

But, if you do end up using winsock, DON'T use ANY of the WSA___() functions, or you'll screw yourself out of portability (and a good program). The rest of them should port quite smoothly to other OSs.

My Sockets Class is almost done for winsock...I'll post a link when I'm happy with it and have tested it. Then I'll make a Berkely port of it.
Excellent, good luck with that. Where are you going to go with it from there?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement