Example of calling a C++ socket server from a java client
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   neelopher_michael
Posted On:   Friday, October 3, 2003 09:33 AM

How to call a C++ socket server from a java client


I need an example of how to call a C++ socket server from a java client. This is very urgent. Could someone please help me out with this. I already have a C++ socket server class. I need to create a java client which I can use in Oracle to send and recieve data from the C++ server.


The java client would send and receive a string from the C++ server. I then have use the string coming back in an Oracle procedure.



Any help would be appreciated.



Thanks

Neelopher

Re: Example of calling a C++ socket server from a java client

Posted By:   Anonymous  
Posted On:   Thursday, October 9, 2003 01:07 PM


Are you sure this is a JNI question? If I understood correctly, all you really want o do is CONNECT to the C++ socket server.



To do this, just use the Socket class in the java.net package.



-JG

Re: Example of calling a C++ socket server from a java client

Posted By:   Praveen_AB  
Posted On:   Thursday, October 9, 2003 01:24 AM

First of all you need to have a dll of the Socket Server in your C++.


Write your java code with the native method and its implementation in it. First compile your code to get the class file.


Then use to get your .h file. Run the program . It should call your SocketServer.


Make sure you either place your dll in the project folder or in the system path for the java class to find it at runtime.




Example:

To send to Socket server


public class Test

{

//Declare the method..

//This method should be defined in your dll also

public native void send();

static {

//Load your dll

System.loadLibrary("library-name");

}


public static void main(String[] arg)

{

new Test().send();

}

}


Same way you can have receive method to get the data from Socket.

Refer the following url to get the details about JNI programming and the datatype mapping between native code and java.




http://java.sun.com/docs/books/tutorial/native1.1/index.html


Hope I could help you.
About | Sitemap | Contact