The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

TCP/IP newbie questions

Hi,

So far, I've always developped traditional GUI applications in C++ for Windows.

Now, I'd need to develop a client/server application and I'm lost, wondering about very basic questions.

For example : with traditional apps, the view classes can directly call public methods on non-graphical objects (for instance : getName() or getDuration() or setXXX()). In a client server app, the non-graphical objects are on the server side. How can the view classes, on the client side, call methods on objects living on the server side ? I have the feeling it is just impossible, but I'm not sure...

So far, I always used Qt and found the signal/slots paradigm very handy, but I just don't see how it can be applied through a TCP/IP connection : is there any chance I can still use it, or is it better to forget it ?

Well, I have many more questions, but I'll stick to the above for now.

If you have any recommandations or hints, I'll appreciate them greatly.

Thanks,
Jerome
Jerome Send private email
Tuesday, July 01, 2008
 
 
You do the following:

1) Establish a network connection from the client to the server
2) Send a request message from the client to the server, which includes the name of the method to be invoked, and any parameters. How you encode this message is up to you; typical message encoding formats include text, binary, and/or XML. For example, a newline-delimited text format:

  CalculateAverage
  14
  3
  122

3) Receive the message on the server. Decode the message. Do what the message tells you to (for example, invoke the "CalculateAverage(14,3,122);" method).
4) Send a response message from the server to the client, which includes the method's return code (and/or any [out] parameter values).
5) Receive the response message on the client and decode it.

There are libraries and/or OS APIs which do this (message packing and unpacking) for you. On Windows, for example, there's "DCOM"; see also "Web Services", and others.
Christopher Wells Send private email
Tuesday, July 01, 2008
 
 
The thing to remember, however, is that sockets are not message-oriented.  They just send bytes ... one after another.

If you want to send a message, you will need to write some code to serialize/deserialize it to an array of bytes, and then on the receiving end, be able to recognize when you have a complete message (you'll need some sort of signature, or a fixed-length message).

Be aware that the network can split your serialized message into 2 or more packets.  And that the end of one message and the start of the following message might be in the same packet.
xampl
Tuesday, July 01, 2008
 
 
Thanks for your explainations.

I'm still having a problem understanding how, when a message is received (which will be the name of a method to call), I can figure out for which object it is aimed, and how I'm going to call the method of this object, knowing the methode's name (I'm developping in C++) ?

Jerome
Jerome Send private email
Tuesday, July 01, 2008
 
 
I think that objects are created on the server; object handles (analogous to an OS file handle) are returned to the client; the client then passes the object handle (together with the name of he method and any parameters) to invoke a method of a specific object.

The API which is exposed by the server is likely (at some level) to be a flat, C-like, static API, one of either ...

class IPuppyFarmSingleton
{
public:
  class Puppy; //opaque
  typedef Puppy* PuppyHandle;
  virtual PuppyHandle createPuppy() = 0;
  virtual void Bark(PuppyHandle) = 0;
}

... or ...

class StaticRemotePuppyFarm
{
public:
  class Puppy; //opaque
  typedef Puppy* PuppyHandle;
  static PuppyHandle createPuppy();
  static void Bark(PuppyHandle);
}

Some layer of the code (within the client) may expose the static Bark method to the application code as an object method:

class Puppy
{
  void Bark()
  {
    //delegate to the StaticRemotePuppyFarm class
    //in order to execute this method on the server
    PuppyHandle puppyHandle = this;
    StaticRemotePuppyFarm::Bark(puppyHandle);
  }
}
Christopher Wells Send private email
Tuesday, July 01, 2008
 
 
If you are making function calls across a socket, one clean and fairly standard way of doing that in this day and age is to do it in a RESTful manner.  Its a fairly trivial task to get a REST interface up and running, and as long as you don't care too much about saving every little bit over the network, it is fine.

There are also lots of standard ways of doing it.  Think soap (gsoap is free), or even getting fancy with zeroconf (avahi, or bonjour are other names for it).  That way your server can advertise itself and its capabilities and the client can simply subscribe to the right soap methods.

I hate to say it, but you are about to jump headfirst into learning network programming with this task!  But have fun, and absorb it like a sponge, it is good experience.
Spyplane
Tuesday, July 01, 2008
 
 
If what you want to do is make method calls on remote objects, then CORBA (or something like it) is probably what you want. CORBA has various ways for getting references to objects on remote systems, and once you have a reference to the object, you can call methods on it. In fact, CORBA makes it look much the same as if it were a local function call.

CORBA has bindings and libraries available on many languages and on many systems.

One thing to watch out for: It's easy to think of CORBA calls as being just like local function calls. THEY AREN'T! They are much more likely to have errors, and they are NOT fast!

Even if it's not the right tool for you, look at it enough so that you can understand it's basic concepts. That will give you an understanding of one way things can be done, and probably lead you to other tools which may be more suited to your app.
Michael Kohne Send private email
Tuesday, July 01, 2008
 
 
Christopher Wells Send private email
Tuesday, July 01, 2008
 
 
My example of the "Puppy" class was misleading. It should probably be more like:

class ClientSidePuppy
{
public:
  //instantiated using a PuppyHandle value returned from the server
  ClientSidePuppy(PuppyHandle puppyHandle)
  : m_puppyHandle(puppyHandle)
  {}

  void Bark()
  {
    //delegate to the StaticRemotePuppyFarm class
    //in order to execute this method on the server
    StaticRemotePuppyFarm::Bark(m_puppyHandle);
  }
private: //data
  const PuppyHandle m_puppyHandle;
}
Christopher Wells Send private email
Tuesday, July 01, 2008
 
 
I thought CORBA was for Unix, or it available on Windows? But DCOM is Windows' solution to the problem, anyway, and probably a lot of overkill if you're not used to COM or are running over a WAN (because of all the security headaches).

For more concepts behind the topic, google "remote procedure call."
Bob
Tuesday, July 01, 2008
 
 
Thank you everybody for your answers and your help ! 

I think I definitely need to have a much closer look to Corba and Soap, at least to understand better the different aspects of remote calls.

I'm sure I'll soon have more specific questions ! :-)

Thanks,
Jerome
Jerome Send private email
Wednesday, July 02, 2008
 
 
Corba is available on everything but it is complicated to use, DCOM managed to combine the existing complexity of COM with the extra 'features' of network programming.

If you know the platforms at both ends (or ideally if they are the same) then there are a lot of simpler systems.
RPC is the most obvious, there are RPC packages for windows and most languages. Or on windows you could just use .NET remoting.
Soap and XML-RPC are useful if you have to get through other peoples firewalls since they package the message over HTTP. Being a standard there are also lots of tools to debug the messages but it might be overkill for large amounts of messages sent inside a client-server system.
Martin Send private email
Wednesday, July 02, 2008
 
 
Are you married to C++? .NET makes this kind of thing cake with its SOA plumbing - remoting in 2.0, WCF in 3.0/3.5.
Andrew Badera Send private email
Thursday, July 03, 2008
 
 
We recently used ONC RPC to remotely invoke methods on Solaris from Windows and vice versa. It is a very old binary-coded version of RPC, but I think it can be great for the simplest uses (where CORBA would be overkill). I guarantee you can have a working prototype in one afternoon (without any prior exposure to ONC RPC)!
Nikola Gedelovski Send private email
Friday, July 04, 2008
 
 
"Are you married to C++? .NET makes this kind of thing cake with its SOA plumbing - remoting in 2.0, WCF in 3.0/3.5. "

I am kind of married to C++.  I don't want to move to .NET because I don't want to stay married to windows for ever.  With C++, I at least have a chance to move to Linux or Mac in the future.  In fact I wrote my own C++ like compiler and write my programs in that.  That makes it kind of easier than programming directly in C++.

As for the OP, why don't you try to write or study a http server and client to see how it works.  You can pass parameters to the server as http '?' variables and parse them.  If you want to secure the communication between server and client, study https also.  Lookup OpenSSL, though I think at this point it will make you dizzy.
dd
Friday, July 11, 2008
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz