Advertisement

[java] Java Networking for a C++ Game

Started by September 22, 2000 11:04 AM
17 comments, last by archon 24 years, 3 months ago
This is a general question, so let me know if I need to be more specific, but I''m thinking about making a networked game and I know Java pretty well, but networking not at all. My question is, do you think it would be possible to use Java for the synching and C++ for the game code? I''ve heard Java is faster than C++ online.
this is just a theroy I thought up in a couple of mins.
you could develop a servlet then have your c++ app send different types of packets to the servlet giving back the data you want. I think it might be better if you were more specific on what you are stating. I am not sure of your direct question

I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
I wish there was a button on my monitor to turn up the intellegince. Theres a button called 'brightness' but it doesn't work
Advertisement
As a general rule, function for function Java will rarely, if ever, be faster than C++. *assuming both are properly written*

It is possible to communicate from C++ application to Java and back to C++ app. There are some things to consider though. Serialization will add a layer ''gunk'' to your network code and you''ll have to deal with it in your C++ app in a way that is less elegant than what you do in Java.

Depending on the platform, the ''optimal'' sockets design will vary. On Windows, you have Winsock 1.1 and 2.0. Winsock 2.0 Overlapped I/O is generally considered to be the most effective method, with IO Completion Ports being the choice on NT/2K. For BSD/Unix, blocking sockets work well for some cases, non-blocking work better for others.

You''ll just have to read up on the sockets API and decide which is best for your case. I have a lot of experience developing winsock applications, let us know what your target platform is and what you need to do and I might be able to offer some suggestions.

Thanks for the suggestions. Essentially the game will run on windows initially, on the client side, and the server could be the most reasonable/cost effective alternative available. Though I haven''t researched hosting, and imagine I''d end up running the app on someone else''s machine.
My direct question would then be:

The game itself will be a BAD 3-D first person roamer, with an expansive world bereft of terrain. I plan to use the natural grid elements of a map as the scenery for the most part, but intend to also have a much more sofisticated interface for actual battles. Like Archon. So, considering that C++ will have to be used for the secondary interface, for a cool real time battle to take place, would it be worth it to code the "roaming" section of the game in java?

I hope that was more clear. And yes, I have alot of researching to do, if you could point me in the direction of some books/articles on the networking/multiplayer topics, that would be great.

And I heard Java was faster than C++, or had the potential to be so, in the context of Corba and COM. Assuming there was an additional layer(not sure exactly where) between clients and server anyway, java was supposed to take advantage of the added high-level logic better than C++.......just something I read....

Thanks Again,

archon
Java is faster than C in the average. Sun claims that Java at one point be as or faster than C++ someday


I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work

Edited by - ARCHIGAMER on September 22, 2000 6:01:55 PM
I wish there was a button on my monitor to turn up the intellegince. Theres a button called 'brightness' but it doesn't work
Well, COM is built on C++ VTables, so I''d be sceptical of any claims that Java is faster than C++ in accessing COM objects. Although I have to say that even I was impressed with the Java 1.3SDK / Runtime performance, and I''m not a big Java supporter.

"Java is faster than C in the average. Sun claims that Java at one point be as or faster than C++ someday"

Care to clarify that one a bit ArchiGamer? It''s generally accepted that properly written C is a tad faster than C++, so how could it be faster than C now, and hope to be faster than C++ someday? Not trying to be a punk, but I don''t like spreading misinformation. I have yet to see any official reviews / tests that claim that Java is faster than C or C++. Let me know if you have the URL for any.

And now on to the original subject. If you''re going to learn enough C++ to create the user interface for a 3D game, I''d suggest just using it for the whole thing. Switching back and forth would be slow at best.

http://www.stardust.com/

is a good place to start out for Winsock questions. They also have a Winsock 2 mailing list that has a lot of people who are well respected in the field. It''s not directed at games, so I''d subscribe and wait a couple days to get the feel for what kinds of questions get asked there.

Anyway, hope that helps some.

Advertisement
I read that in a book while studying java. Plus if you look in the thread list look for a post about it. is is called "Java faster than C in the average" i believe or something similar

I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
I wish there was a button on my monitor to turn up the intellegince. Theres a button called 'brightness' but it doesn't work
heres a link to the post here

I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
I wish there was a button on my monitor to turn up the intellegince. Theres a button called 'brightness' but it doesn't work
I am not joining the discussion about what is best C++/Java/C, because it is pretty fruitless and has been parts of this forum numerous times.

Doing network with Java is pretty easy, more so than with C++, but according to some PostMortem article (can''t remember which) I read in Game Developer magazine once there was some people that did their game in C++ but put all networking in Java.
The conclusion was that working with networking in Java was a blis but because they had a need to interface networking on many levels of their system the interface between Java and C++ became so large that it actually took them longer to do than doing it all in C++ - it actually ended with them skipping Java networking and doing it all in C++.
They empahasized that they though Java was good but that their interface needs for the networking made it unsuitable.

In conclusion, you can use Java for networking, but it is most useful if most of your application data you need to send over the network already is in Java format. Otherwise, all the ease of use will be eaten up.

I personally think that one should write ones game in java first (except the graphics engine - those are best done in C++) and then isolated bottlenecks afterwords with a profiler and then recode those parts in C++. If you do this you will have a good advantage of using Java networking and many other Java features.

One thing that I myself has begun to do is to take 3rd party engines (the 6DX 3D engine for instance) provide thin Java wrappers for them and then do the control code in Java. Most of the time the game is down in the engine anyway doing rendering so the fact that the control code is written in Java doesn''t make much difference to the overall speed.

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Thanks for all the replies....Looks like I have some research to do.


I think I''m going to work on a 3D graphics engine in C++ and then try and convert it to Java. Should be a fairly interesting experiment at the very least....
Felonious, your idea to keep the control code in Java sounds right to me. Are you suggesting a Java wrapper on top of the entire game engine? That way all the networking code can remain in Java with a performance hit for the wrapping, correct? As far as going back and forth between the languages, are there any universal data types or are they so simple that they wouldn''t be useful? I guess an interpreter class would be the best way to do it....class babblefish {


At the very least, if its too slow I can always unwrap the code,
Merry Christmas

archon

This topic is closed to new replies.

Advertisement