#### Archived

This topic is now archived and is closed to further replies.

# Cross-platform Sockets

This topic is 6365 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

-=Warning=-[br] I am the delegated leader for a small group of artists and programmers just starting out into the world. Most of the programmers are vets of the database programming realm, the artists have been into computers for a while. Assume no bottom line while reading this. Now for the serious stuff...[br][br] -=Vapor=-[br] The project itself is grandiose, and very well be vaporware by the end of the summer, but for now, the purpose that the group was assembled for is clear: we must produce a bit of very high-quality work. To do otherwise is professional suicide. Our current project is a C++ port/modification of a Java graphical MUD client (no specifics), which currently interfaces with its compliment, a Java server (servlet?) using the builtin java.net.* libraries. The layout of the program is simplistic and would ordinarily be no match for this team''s experience and knowledge... except for the fact that the Java language is dumbed-down, interpreted, and lets the programmer get away with bad habits. Clearly, a rewrite and reimplementation is in order. Herein lies my problem: I have no working knowledge of the internal network aspect of Java, which is essential in porting a client/server game (duh). Now for the question: [br][br] -=Cross-Platform=-[br] I am not a Windows(tm) guy. I am a UNIX guy. I''m comfortable with that, and SDL seems to suit my purposes much better than struggling through Xlib code until I can eke out a display. Display itself is not my problem, which is why I''m posting here with the "Sockets" in the title and the reference to networked applications. My question is twofold:[br] * How can the translation from Java to C++ take place smoothly (i.e. without reimplementing the network libraries) in the networking department?[br] * How can I be sure that all of the code that I write will translate smoothly across the platform boundary (from BSDSocks to WinSock2 and vice versa)?[br] I understand that fundamentally, all that is required are a few
  #ifdef
s, but I am interested in the potential hazards in using such systems.[br][br] -=Wrap=-[br] Put simply, I need help in porting the network aspect of a Java-based game to C++. Not just for myself but for my team. We aren''t green, but we''re new to games. I''m not going to come back on and complain that my "Makefile is borked so its you''re fault" (I wouldn''t use that grammar anyway), so you can vent your ideas freely, and my brain will sort them out. Remember that I''m aiming for cross-platform compatibility, and that if it doesn''t compile on at least *NIX and Win32 (like if it uses DirectPlay), it''s not a valid solution. Wow. I laid a whole lot of words down to explain a very simple thing. [br][br] -=Disclaimer=-[br] Like I said, assume no bottom line (I''m not going to copy your code and litigate over my claim to it). I would appreciate concise, technical answers preferably from professionals with knowledge in this area, but newbies and kiddies are allowed, too. I''m not biased against kids or the otherwise incoherent, but I''d like to make a distinction.[br][br] Thanks,[br] eisenwulf

##### Share on other sites
Both Win32 and Unix provides sockets which work much the same way and can do the same things as Java Sockets. The problem is that the functions don''t have the same prototypes and you have to write almost the same things twice.

If I were you, I would try to encapsulate all my socket stuff into classes which works like the Java ones. It should be easier to port the application after that.

I would do something like this :

  class Socket{ private: // stuff public: void method_with_the_same_name_as_the_java_class() {#ifdef WIN32 // Win 32 stuff#endif #ifdef UNIX // Unix/Linux stuff#endif } ...};

It''s perhaps not very elegant but once the grunt job is done (the "magic classes"), it''s very convenient. Writing these classes shouldn''t be very long. You just have to make a pretty interface which calls already defined functions.

You can find a couple of tutorials about WinSocks (Windows sockets) on this site. Finding information about Unix Sockets should not be difficult if you are a Unix guy.

Note that if you use SDL you may be interested in SDLnet. It''s a cross-platform network oriented API. You can find it in the library section of the SDL site (www.sdl.org). However there is no documentation (you have to look at the headers files) and it is still in beta. But even if you don''t use it, checking the source code may give you some good ideas.

Hope it helps.

PS: You don''t have to put [br] in your messages.

1. 1
2. 2
JoeJ
17
3. 3
4. 4
frob
11
5. 5

• 13
• 16
• 13
• 20
• 13
• ### Forum Statistics

• Total Topics
632186
• Total Posts
3004637

×