Find in this group all groups
Unknown more information…

j : 5 February 2007 • 5:58AM -0500 PlainSocketImpl.c and my own socket implementation
by Leandro Melo de Sales


Hi Steve and others,

   I'm trying to create socket implementation for a transport protocol
different of TCP and UDP (in linux), but similar to TCP, since it is a
oriented connection protocol. I want to integrate it into the JVM. So,
I wrote a C to Java wrapper to call native methods by using JNI and
when I run the connect test, after create the socket and the connect
to a remote, I can send data through out this socket. But now I want
to extend the java socket functions to support my new socket. I'd like
to know what is the correct process to do this. There are so many
classes, abstract classes and interfaces which I can use, and as I
understood, I did the job as following, but I don't know if I'm doing
the right stuffs since after some attempts I can't create the socket
like I wish.

The steps that I'm following is:

1 - I create a class named NativeSocket.c which implements basic c
methods, such as create socket, connect and so on. I also create a
class which, by using JNI, I can call all native
2 - I create a class named MySocketImpl which extends the SocketImpl
abstract class and implement the abstract methods using my native
implementation described in the step 1;
3 - I create I class named MySocketImplFactory which implements the
SocketImplFactory interface, the single method createSocketImpl;
4 - The method createSocketImpl create and return a instance of
MySocketImpl described in the step 2;
5 - I create a class named which extends
as follows:

public class MySocket extends Socket {

static {
MySocketImplFactory aMySocketImplFactory = new MySocketImplFactory();
try {
} catch (IOException e) {

public MySocket(String host, int port) throws IOException {
super(InetAddress.getByName(host), port);


6 - I create a instance of like this:

Socket mySocket = new MySocket("localhost", 10000);

Is this the right steps to create my own socket implementation by set
the socketimplfactory of the class? When I create
MySocket instance the method bind is called but I was expecting that
the right method to be called is connect instand of bind. Why the bind
method is called? BTW, what shoud I do in this bind method? I also try
to understand the java internals implementation (the native codes) and
in my case, do I have to worry about the SecurityManager or since I'm
extend Socket implementation is this alredy done?

Please, any clue/suggestion will be greatfully accepted.

Thank you in advance,


To UNSUBSCRIBE, email to java-linux-request@java...
with a subject of "unsubscribe". Trouble? Contact karl@blac...

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.