java.net package - Override UDP transport

萝らか妹 提交于 2019-12-12 06:08:35

问题


I need to override the default implementation of DatagramSocket transport i.e., PlainDatagramSocketImpl and I found that java provides a way to do this via DatagramSocketImplFactory class. However my requirement is to use my own class for a very specific case and to use the default UDP socket transport for all other cases. Essentially adding an if-else clause in SocketFactory class which will instantiate my class if a condition is met, else instantiate the default transport.

My dilemma is that I cannot instantiate PlainDatagramSocketImpl inside my socketfactory since this class is visible only inside "java.net" factory. Another option would have been to put my SocketFactory class inside java.net package but then java does not allow it. I tried adding "permission java.lang.RuntimePermission "defineClassInPackage.java.net";" in policy file and then define my SocketFactory in java.net package but this doesn't seem to work either. Any ideas ?

来源:https://stackoverflow.com/questions/28439229/java-net-package-override-udp-transport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!