473,699 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What to use to network a simple battleship game?

Basically I want to create a battleship game that can be played by having
two clients connect to it. I was wonder what the best networking principal
would be. Basically I suppose I would have to pass an int value or something
representing the x,y coordinates of each shot. Should I use some type of
Socket programming or RMI or what else should be used|?

Thanks

Jul 17 '05 #1
1 8089
C-man wrote:
Basically I want to create a battleship game that can be played by having
two clients connect to it. I was wonder what the best networking principal
would be. Basically I suppose I would have to pass an int value or something
representing the x,y coordinates of each shot. Should I use some type of
Socket programming or RMI or what else should be used|?

Thanks


It depends if you want to learn or if you want it to be easy to work.
You could use RMI but if you've never done sockets, why not do that?

MulticastSocket s is data that is sent to a particular adress but is
"broadcaste d" to all the nodes on a network. But be carefull its not
routeable (meaning that routers won't foward it onto the other network,
unless they have a wierd configuration thing). So if its just meant to
talk within a school lab, then you can use those. They are pertty easy.

You can use either UDP or TCP programming. UDP doesn't guarantee that
the client will get the data. Its like an answering machine. You say
"Send it to there", but there is no 'connection' per se. Its a lot
faster, but your data might not get there. UDP packets are called
DataGrams and there is stuff in java to do them. DatagramPacket for
example.

That leaves TCP programming. This is what you use when you use a web
browser. The web browser connects and you get all of the data. Its
slower but you are guaranteed that the data packets will get to you in
order.

To do that you should check out ServerSocket and ClientSocket. This is
usually how the application loads up. Remember this means that you have
to make your own protocol between the clients (IE: first byte is the
version of your software, then what type of packet it is (data like your
oponent shot x y, or the type of ship is stored where etc...)). This is
a lot of fun, do it on paper on in word and print it out, it will help
you during programming.

I don't know if it would help you but check out andre.bonin.ca under
projects, there is a report with the "Marathon" project. It was a
netmeeting-like (voice over ip) application and there is a big
description on the protocol and why stuff was used).

Usually when your application loads up, it starts listeningon a port
(lets say 5670 or whatever). When your game tries to connect to the
remote player, it instantiates a ClientSocket to the IP address of the
remote system on port 5670. When properly connected, you can send the
data like the data like the person's nick name and his boats and stuff.
The remote computer should dry then to conect on your local port 5670
to do the same.

Instead of doing a protocol you can also use serialized objects. A
friend of mine did that and he says it worked quite well. The
Serializeable interface is what you want here. It takes a class and
makes a "string" out of it that you can pass down the pipe. You can
then unserialize it at the other end and use it as an instance of an
object. Pretty cool, and that would elliminate you haveing to write
much of your protocol.

Anyway just my thoughts, the net a is pretty good resource for most of
this stuff if you want to learn more.

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
14758
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
11
4036
by: Van Nastring | last post by:
I believe it is c++ right? Why don't they use c#?
4
1194
by: sp000n | last post by:
While teaching myself to program, I've undetaken a little game project akin to Battleship only it's not turn-based. The stand-alone version is working fine but I'd like to expand it to include a head-to-head feature. With the program running on two computers, I wish to manually input the IP of the opponent into each. Then, I expect each event handled by one program to generate a network message received and interpeted by the opponent. I...
1
1530
by: iwdu15 | last post by:
hi, im trying to program the game battleship but i cant figure out how to code how people can place the ships and keep track of it. Ive been trying and researching for a couple days now and am at the end of my rope...if anyone cal help thatd b awsome. i have a 10x10 picturebox grid initialized into a 2d array to hold them. i just need to have a way to have them pick where they want their ships and keep track of it....thanks to anyone...
24
9379
by: gonzo86 | last post by:
Hey, Im kind of new to C++ and I'm working on making a Battleship program. I need to be able to output a screen with just dots on it for when people havent tried those spots and then be able to switch it with the characters in my array after they have been picked. This is the code I have so far. Right now all all I want to do is make a game where you have to sink the computers ships in less than 50 turns. Thanks for any help that I get. ...
5
5994
by: muna123 | last post by:
hi, I need help in battleship game here is my code: #include <stdio.h> void draw_game(char board, int maway, int mleft, int score, char prevmove);
0
1038
by: Richard Szlachta | last post by:
Readers of python mailing list of all ages and systems, I'd like to introduce you program called ' Piskworky '. It is written in python, uses tkinter gui and is made for playing game known as five-in-row. Game is pure multiplayer (two-player exactly ;) and it does it's synchronization via jabber network. Well, check the website: http://piskworky.ic.cz/
19
6728
by: Olivia Jaden | last post by:
Hi, I was about to create a 8x8 battleship program. there should be 8 ships in total with 1x1 size. However, I do not know how to place the ships randomly. Below are some of the codes that I started after doing some research #include <iostream> #include <windows.h> using namespace std;
0
1551
by: ShadowPhantom000 | last post by:
I Am a Just recently Graduated High school student who took a Java class in school, and created a couple of simple network games... and am now learning c# but I Cant seem to find any good tutorials on making Multiplayer games. Does anyone have a good tutorial? I am looking for something simple that shows how to pass and receive messages from a server application like a chat room or simple game...
0
8620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8887
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.