INTERFACING JAVA & C: RESOURCES 
Author Message
 INTERFACING JAVA & C: RESOURCES

Hi there

I was wondering if somebody could get me started on the following:

I want to interface a C client with a Java server communicating via a
tcp/ip connection. At the moment I need a listing and explanations of
essential concepts and some pointers to good online tutorials and the
like.

I have used C before but I am new to Java (and tcp/ip and client/server
architectures), so it would be nice if your answers are not too jargon
loaden...

Roger



Fri, 23 Aug 2002 03:00:00 GMT  
 INTERFACING JAVA & C: RESOURCES

Roger Said escribi:

Quote:
> Hi there

> I was wondering if somebody could get me started on the following:

> I want to interface a C client with a Java server communicating via a
> tcp/ip connection. At the moment I need a listing and explanations of
> essential concepts and some pointers to good online tutorials and the
> like.

> I have used C before but I am new to Java (and tcp/ip and client/server
> architectures), so it would be nice if your answers are not too jargon
> loaden...

> Roger

   The first idea you have to know, is that each time you want to connect
computers through the net, you have to specify the address of the machines
and the port you are going to use for the communication.
   The second thing youll have to consider, is, as you are using TCP/IP,
which communication protocol are you going to use (TCP or UDP). The main
difference is that TCP makes connection between the server and the client
and keeps it "on" during all the communication (until you close it). It is
like a phone call. With UDP, no connection is made, you just send datagram
packets and the way they arrive is like letters (you put the address and go
to the mail box).
  If you use TCP, in java youll have to work with the classes
"ServerSocket" and "Socket".
   ServerSocket will allow the server to accept clients. When you create a
ServerSocket objetct, at least, youll have to specify the port you are
going to use in order to communicate with the clients.
Example
 ServerSocket servidor=new ServerSocket(8080);
You have prepared the server to recieve clients using port 8080. A
ServerSocket gives you some functions that let you manage the clients, like
"accept()", or  "close()".
   Each time a client makes a connection, "accept()" will accept the
connection and will make a Socket to communicate with the client. "Socket"
class allows you to send and recieve information between computers, (with
TCP communication).
   Example:

 ServerSocket servidor=new ServerSocket(8080);
 Socket enchufe=null;

 enchufe=servidor.accept(); /*The server "servidor" waits until a client
conencts to him. The funcion "accept()" will assign the socket "enchufe" to
communicate with the client that has arrived*/

 In the client youll have to learn, in C,  how to connect to a server
(using  TCP in this case), and using port 8080. Once connection is made,
you just send information though it.
 If you want to use UDP, look for java classes "DatagramPacket" and
"DatagramSocket".

Its a slightly simplified explaination, but I hope  you have good luck.
Bye
   Lobo.



Fri, 23 Aug 2002 03:00:00 GMT  
 INTERFACING JAVA & C: RESOURCES
I would suggest using CORBA to communicate between C and Java.
(www.omg.org) CORBA works like RMI in that you can remotely reference/use
objects with the additional benefit of programming language independence
(C/Java/Ada/etc.)

What you would end up doing is creating an Interface Definition Language
(IDL) definition of the Java server interface compile it with CORBA to
produce "stubs" or client interfaces for C and then have your C client call
the methods in the stubs.  The C client thinks that it's talking to a C
server and the Java server thinks it's talking with a Java client.  CORBA
takes care of translating from C to Java and back as well as transferring
the data across a network (TCP, etc.)

I have used socket communication before between Java & C++ and between C++
(UNIX) and C++ (Windows) and defining custom message definitions and dealing
with byte-ordering is not too entertaining.  If you're doing a simple
application sockets may be O.K.

If you plan to use CORBA, I would suggest looking at the Java Tutorial on
RMI (essentially RMI works the same as CORBA).  Once you get an idea on how
RMI works, check out some of the references on the OMG web site.  The Java
Tutorial provides a better introduction and/or overview of the technology
than some of the CORBA docs.

-- The Craggle


Quote:

> Roger Said escribi:

> > Hi there

> > I was wondering if somebody could get me started on the following:

> > I want to interface a C client with a Java server communicating via a
> > tcp/ip connection. At the moment I need a listing and explanations of
> > essential concepts and some pointers to good online tutorials and the
> > like.

> > I have used C before but I am new to Java (and tcp/ip and client/server
> > architectures), so it would be nice if your answers are not too jargon
> > loaden...

> > Roger

>    The first idea you have to know, is that each time you want to connect
> computers through the net, you have to specify the address of the machines
> and the port you are going to use for the communication.
>    The second thing youll have to consider, is, as you are using TCP/IP,
> which communication protocol are you going to use (TCP or UDP). The main
> difference is that TCP makes connection between the server and the client
> and keeps it "on" during all the communication (until you close it). It is
> like a phone call. With UDP, no connection is made, you just send datagram
> packets and the way they arrive is like letters (you put the address and
go
> to the mail box).
>   If you use TCP, in java youll have to work with the classes
> "ServerSocket" and "Socket".
>    ServerSocket will allow the server to accept clients. When you create a
> ServerSocket objetct, at least, youll have to specify the port you are
> going to use in order to communicate with the clients.
> Example
>  ServerSocket servidor=new ServerSocket(8080);
> You have prepared the server to recieve clients using port 8080. A
> ServerSocket gives you some functions that let you manage the clients,
like
> "accept()", or  "close()".
>    Each time a client makes a connection, "accept()" will accept the
> connection and will make a Socket to communicate with the client. "Socket"
> class allows you to send and recieve information between computers, (with
> TCP communication).
>    Example:

>  ServerSocket servidor=new ServerSocket(8080);
>  Socket enchufe=null;

>  enchufe=servidor.accept(); /*The server "servidor" waits until a client
> conencts to him. The funcion "accept()" will assign the socket "enchufe"
to
> communicate with the client that has arrived*/

>  In the client youll have to learn, in C,  how to connect to a server
> (using  TCP in this case), and using port 8080. Once connection is made,
> you just send information though it.
>  If you want to use UDP, look for java classes "DatagramPacket" and
> "DatagramSocket".

> Its a slightly simplified explaination, but I hope  you have good luck.
> Bye
>    Lobo.



Mon, 26 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Linker error "relocations remain", shared object, Solaris, gcc, ld, java, java native interface, cplex

2. Newbie: separate big .cs file into small .cs files

3. dual interfaces & more than on interface

4. Fork, Java Native Interface

5. Equivalent of java Runnable interface?

6. Interface with environment? (similar to Java)

7. Java Native Interface

8. Replacing a Java User Interface with MFC

9. Update: Resource Standard Metrics for C, C++ and Java

10. Notice: Resource Standard Metrics, C C++ and Java

11. java applet as resource?

12. java applet as resource?

 

 
Powered by phpBB® Forum Software