Re: PlainSocketImpl.java PlainSocketImpl.c and my own socket implementation
"Leandro Melo de Sales" <[email protected]> Mon, 5 Feb 2007 02:54:08 -0300
| Newsgroups | gmane.comp.java.linux.general |
|---|---|
| Message-ID | <[email protected]> |
Still in this discussion, in the constructor of my MySocket class, I call super(host, port) and set the SocketImplFactory passing my factory as argument. When I create a instance the method bind is called due to Socket implementation, but instand of the bind method receive the host and port parameters passed when I create MySocket instance, the method bind receives host=0.0.0.0 and port=0, but right before send these values as arguments (host and port) I call a System.out.println(host + port) and it is printed the values passed to MySocket constructor. What is wrong? Please, someone to help me. Thanks, Leandro 2007/2/4, Leandro Melo de Sales <[email protected]>: > 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 NativeSocket.java which, by using JNI, I can call all native > methods; > 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 MySocket.java which extends java.net.Socket > as follows: > > public class MySocket extends Socket { > > static { > MySocketImplFactory aMySocketImplFactory = new MySocketImplFactory(); > try { > Socket.setSocketImplFactory(aMySocketImplFactory); > } catch (IOException e) { > e.printStackTrace(); > } > } > > public MySocket(String host, int port) throws IOException { > super(InetAddress.getByName(host), port); > } > > } > > 6 - I create a instance of MySocket.java 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 java.net.Socket 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, > > Leandro > ---------------------------------------------------------------------- To UNSUBSCRIBE, email to [email protected] with a subject of "unsubscribe". Trouble? Contact [email protected]