ITPub博客

首页 > 应用开发 > IT综合 > cnwap不支持push

cnwap不支持push

原创 IT综合 作者:wangzh3 时间:2012-06-26 14:58:45 0 删除 编辑
因为CMWAP是HTTP Proxy,而Java SocketChannel不支持代理,Socket只支持SOCKS(防火墙)代理,不支持HTTP Proxy。 Java源码也进一步论证了使用Socket HTTP Proxy无法连接HTTP服务器的问题。上层封装的URLConnection或HTTPURLConnection,虽然支持HTTP Proxy,但不支持主动监听模式的推送应用。 如果需要推送服务支持CMWAP网络,则需要自己实现一套Socket HTTP Proxy。 jdk1.6.0_26 /** * Creates an unconnected socket, specifying the type of proxy, if any, * that should be used regardless of any other settings. *

* If there is a security manager, its checkConnect method * is called with the proxy host address and port number * as its arguments. This could result in a SecurityException. *

* Examples: *

  • Socket s = new Socket(Proxy.NO_PROXY); will create * a plain socket ignoring any other proxy configuration. *
  • Socket s = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("socks.mydom.com", 1080))); * will create a socket connecting through the specified SOCKS proxy * server. *
* * @param proxy a {@link java.net.Proxy Proxy} object specifying what kind * of proxying should be used. * @throws IllegalArgumentException if the proxy is of an invalid type * or null. * @throws SecurityException if a security manager is present and * permission to connect to the proxy is * denied. * @see java.net.ProxySelector * @see java.net.Proxy * * @since 1.5 */ public Socket(Proxy proxy) { // Create a copy of Proxy as a security measure if (proxy == null) { throw new IllegalArgumentException("Invalid Proxy"); } Proxy p = proxy == Proxy.NO_PROXY ? proxy : sun.net.ApplicationProxy.create(proxy); if (p.type() == Proxy.Type.SOCKS) { SecurityManager security = System.getSecurityManager(); InetSocketAddress epoint = (InetSocketAddress) p.address(); if (epoint.getAddress() != null) { checkAddress(epoint.getAddress(), "Socket"); } if (security != null) { if (epoint.isUnresolved()) epoint = new InetSocketAddress(epoint.getHostName(), epoint.getPort()); if (epoint.isUnresolved()) security.checkConnect(epoint.getHostName(), epoint.getPort()); else security.checkConnect(epoint.getAddress().getHostAddress(), epoint.getPort()); } impl = new SocksSocketImpl(p); impl.setSocket(this); } else { if (p == Proxy.NO_PROXY) { if (factory == null) { impl = new PlainSocketImpl(); impl.setSocket(this); } else setImpl(); } else throw new IllegalArgumentException("Invalid Proxy"); } } http://www.java2s.com/Open-Source/Android/android-core/platform-libcore/java/net/Socket.java.htm /** * Creates a new unconnected socket using the given proxy type. When a * {@code SocketImplFactory} is defined it creates the internal socket * implementation, otherwise the default socket implementation will be used * for this socket. *

* Example that will create a socket connection through a {@code SOCKS} * proxy server:
* {@code Socket sock = new Socket(new Proxy(Proxy.Type.SOCKS, new * InetSocketAddress("test.domain.org", 2130)));} * * @param proxy * the specified proxy for this socket. * @throws IllegalArgumentException * if the argument {@code proxy} is {@code null} or of an * invalid type. * @throws SecurityException * if a security manager exists and it denies the permission to * connect to the given proxy. * @see SocketImplFactory * @see SocketImpl */ public Socket(Proxy proxy) { this .proxy = proxy; if (proxy == null || proxy.type() == Proxy.Type.HTTP) { throw new IllegalArgumentException( "Proxy is null or invalid type"); } InetSocketAddress address = (InetSocketAddress) proxy.address(); if (null != address) { InetAddress addr = address.getAddress(); String host; if (null != addr) { host = addr.getHostAddress(); } else { host = address.getHostName(); } int port = address.getPort(); checkConnectPermission(host, port); } this .impl = factory != null ? factory.createSocketImpl() : new PlainSocketImpl(proxy); }

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/47869/viewspace-1058648/,如需转载,请注明出处,否则将追究法律责任。

上一篇: setsockopt选项
请登录后发表评论 登录
全部评论
  • 博文量
    301
  • 访问量
    10828971