• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Triad_prague

communicating between C++ server and Java client app

9 posts in this topic

Hi fellow developers, I hope you're all fine and well.

Well I got a few question here. Basically I managed to start a simple chat application with movable avatars (like the sims multiplayer). I could code the server in C++, but the client app is meant to be installed on android mobile devices, thus I'd better code it in java.
(I'm quite fluent in C++, but java is quite new to me, although my friend said the transition wouldn't be too painful. I've read several pages of a java book and the syntax is quite similar to C++)

Now comes the complex part, which is communicating between the two languages. Here's several questions I got in my head:

1. What kind of issues that I should anticipate?
2. Aren't the sizes of datatypes in both language the same? what about the byteorder?
3. I use winsock in C++, I wonder if there's such equivalence in java.
4. I'm planning to buy a book that teaches networking in java apps. Do you have some good suggestions? (my current book is for beginner. It doesn't have networking sections in it [img]http://public.gamedev.net//public/style_emoticons/default/mellow.png[/img] )

well, that's all I have in mind. I hope you guys could shed some light here. I'm so eager to learn java [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] .
0

Share this post


Link to post
Share on other sites
Have you considered writing the server in Java? This might simplify some things.

As for your questions:
[list]
[*] 1. What experience do you have writing portable code?

[*] 2. C++ does only gives minimum data type sizes, and does not guarantee byte order. You'd have the same issue writing a portable C++ client talking to a portable C++ server. The solution here is to define what the data should look like on the wire, and then ensure that each peer will correctly pack and unpack the data from this format. You can base the wire format on one that is convenient for one of the implementations (e.g. it might map directly to a big endian C++ unpadded structure written in terms of explicitly sized types).

[*] 3. Java has various Socket classes. They are essentially an object oriented version of a berkley-esque API, so will not be dissimilar to WinSock. Probably easier, if anything.

[*] 4. I have no specific suggestions, but I would say that if you're experienced in network programming then you probably don't need a book. There are lots of good examples on the internet that will get you up and running quickly.
[/list] Edited by rip-off
1

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1352551125' post='4999627']
Have you considered writing the server in Java? This might simplify some things.

As for your questions:[list]
[*]1. What experience do you have writing portable code?
[*]2. C++ does only gives minimum data type sizes, and does not guarantee byte order. You'd have the same issue writing a portable C++ client talking to a portable C++ server. The solution here is to define what the data should look like on the wire, and then ensure that each peer will correctly pack and unpack the data from this format. You can base the wire format on one that is convenient for one of the implementations (e.g. it might map directly to a big endian C++ unpadded structure written in terms of explicitly sized types).
[*]3. Java has various Socket classes. They are essentially an object oriented version of a berkley-esque API, so will not be dissimilar to WinSock. Probably easier, if anything.
[*]4. I have no specific suggestions, but I would say that if you're experienced in network programming then you probably don't need a book. There are lots of good examples on the internet that will get you up and running quickly.
[/list]
[/quote]

Firstly, I never code anything in Java and compile it in linux. And I'm mostly comfortable with C++. Plus I heard java is quite unsuitable for resource hogging, low-level task that most server do. Correct me if I'm wrong [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

1. I've written a simple platformer game using SDL and C++ and also a simple chat program, and port them to Linux (do they count as portable?)
2. The data would consist of header (id and size), and a stream of bytes following it. I'm mostly worried of endianness between platform/language
3. Hmm now that you've mentioned it, I've yet to see if it's supported in Android. I hope it is.
4. [img]http://www.nocturnar.com/forum/attachments/humor/56306d1348599090-memes-okay-okay_meme_tf2_version_by_jaymewes-d2y3ud5-2-.jpg[/img]
0

Share this post


Link to post
Share on other sites
Java doesn't have to be so bad. Consider that Minecraft is written in Java. As is many large enterprise web applications, such as online banking etc. And if it makes you happy, Java is less resource hogging than Ruby (used by Twitter) or PHP (used by Facebook) or Python (used by Google) :-)

Still, if you want to keep languages separate, you'll need to come up with a way to make sure the languages agree on packet formats and semantics. You have to be very meticulous in how you define each kind of packet you use, and make sure you update both languages at the same time. (Once you ship, you have to do something about older clients connecting, too.) Typically, you'll end up with an IDL (interface description language) of some sort, which takes an abstract description of your packets, and generates code for each language you're using to generate and interpret the bytes on the wire. Example IDLs include Google Protocol Buffers (used by Google,) Apache Thrift (used by Facebook,) Sun XDR (old-school, used by NFS) and many others.
1

Share this post


Link to post
Share on other sites
I don't think you'll run into perfomance problems by writing your server in Java (unless your server logic is filled with a lot of number-crushing stuff). Actually the newer JVM are high-optimized with server side in mind. Take a look at apache MINA, it's a framework to write scalable server software.

But if choose to write your server in C++ (which is a logical decision, as you're familiar with it), just write a low-level protocol (not using boost::serializable or any other fancy seralization library, using [b]primitve[/b] datatypes always minding types size mismacht and using network endian order (big endian)) and you'll be fine.
1

Share this post


Link to post
Share on other sites
[quote name='hplus0603' timestamp='1352567020' post='4999668']
Java doesn't have to be so bad. Consider that Minecraft is written in Java. As is many large enterprise web applications, such as online banking etc. And if it makes you happy, Java is less resource hogging than Ruby (used by Twitter) or PHP (used by Facebook) or Python (used by Google) :-)

Still, if you want to keep languages separate, you'll need to come up with a way to make sure the languages agree on packet formats and semantics. You have to be very meticulous in how you define each kind of packet you use, and make sure you update both languages at the same time. (Once you ship, you have to do something about older clients connecting, too.) Typically, you'll end up with an IDL (interface description language) of some sort, which takes an abstract description of your packets, and generates code for each language you're using to generate and interpret the bytes on the wire. Example IDLs include Google Protocol Buffers (used by Google,) Apache Thrift (used by Facebook,) Sun XDR (old-school, used by NFS) and many others.
[/quote]

Yes, Google Protocols are an even better solution than writing low-level network protocol.
0

Share this post


Link to post
Share on other sites
[quote]
Firstly, I never code anything in Java and compile it in linux. And I'm mostly comfortable with C++.
[/quote]
Presumably you'll be getting fluent in Java as part of or before undertaking this project, in order to be able to write the client.

[quote]
Plus I heard java is quite unsuitable for resource hogging, low-level task that most server do.
[/quote]
That depends on the nature of your game. I expect that for most games that are going to be completed by a single developer or a small team, Java will suffice.

Will all the clients in your game be connecting to one server instance / cluster, or do players create their own servers?
1

Share this post


Link to post
Share on other sites
[quote name='Triad_prague' timestamp='1352543503' post='4999608']I could code the server in C++, but the client app is meant to be installed on android mobile devices, thus I'd better code it in java.[/quote]

What just happened right there? The client environment has nothing to do with the language the server is written in. IP derived protocols are platform agnostic. As long as you take control of your byte ordering and serialization you should be fine.

My one word of advice though, is that you use some tool like wireshark or etc to ensure that your socket IO is as expected at both ends. I ran into a problem once where an IO method I was using was tacking a "\n" on the end of outbound data and it took me a week to figure out what was happening. I could have avoided all of that by just glancing at the data on the wire.

[quote name='hplus0603' timestamp='1352567020' post='4999668']Java is less resource hogging than Ruby[/quote]

Well, Ruby's gotta have somewhere to put in all that extra deliciousness. :wink: Edited by Khatharr
1

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1352570141' post='4999686']
[quote]
Firstly, I never code anything in Java and compile it in linux. And I'm mostly comfortable with C++.
[/quote]
Presumably you'll be getting fluent in Java as part of or before undertaking this project, in order to be able to write the client.

[quote]
Plus I heard java is quite unsuitable for resource hogging, low-level task that most server do.
[/quote]
That depends on the nature of your game. I expect that for most games that are going to be completed by a single developer or a small team, Java will suffice.

Will all the clients in your game be connecting to one server instance / cluster, or do players create their own servers?
[/quote]

Yes, I'm learning Java right now, which is quite weird for some friends since the learning process seems to be "reversed" (they learn java first)

On my app, all clients connect to single authoritative server.


[quote name='Bubsy' timestamp='1352567565' post='4999674']
I don't think you'll run into perfomance problems by writing your server in Java (unless your server logic is filled with a lot of number-crushing stuff). Actually the newer JVM are high-optimized with server side in mind. Take a look at apache MINA, it's a framework to write scalable server software.

But if choose to write your server in C++ (which is a logical decision, as you're familiar with it), just write a low-level protocol (not using boost::serializable or any other fancy seralization library, using [b]primitve[/b] datatypes always minding types size mismacht and using network endian order (big endian)) and you'll be fine.
[/quote]

this is what I'm planning too. I'll be serializing data and not just send the struct/class as "it is". Plus I'll be using htonl() and htons() etc to ensure byte order consistency.

[quote name='Khatharr' timestamp='1352573919' post='4999699']
What just happened right there? The client environment has nothing to do with the language the server is written in. IP derived protocols are platform agnostic. As long as you take control of your byte ordering and serialization you should be fine.
[/quote]

well thanks mate. You've just cleared some doubt here.


Btw, it turns out that java is a lil bit different in that it has no "globals". Gotta wrap the main function within a class, but I guess that's fine. I'm considering writing the server in java too. The curve might get a little steeper, but I'm willing to learn. Besides, this project is not too time critical. I do it in my free time only. I've seen several pros and cons of it. And I decided to stick with it. Anyway, thanks guys. I'll be reading a lot of stuffs tonight, and I'll be back here when things are getting too hard to grasp
[img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]
0

Share this post


Link to post
Share on other sites
[quote name='hplus0603' timestamp='1352567020' post='4999668']
Java doesn't have to be so bad. Consider that Minecraft is written in Java. As is many large enterprise web applications, such as online banking etc. And if it makes you happy, Java is less resource hogging than Ruby (used by Twitter) or PHP (used by Facebook) or Python (used by Google) :-)
[/quote]

Facebook was heavy on PHP, but then they decided to start using C++ more.

I don't have Android experience, but I've heard C++ is an option there.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0