简体   繁体   English

在服务器与客户端之间建立连接时捕获到异常…!

[英]Exception is caught during establishing the connection between server and client…!

hello guy's just written a program for Client and server. 您好,我刚刚为客户端和服务器编写了一个程序。 While i put "127.0.0.1" or "localhost" it works perfectly but while i assign my own ip or may be some of my friend ip. 虽然我放了“ 127.0.0.1”或“ localhost”,但它工作得很好,但是当我分配自己的IP或可能是我的一些朋友IP时。 It doesn't work and give an exception like this 它不起作用并给出这样的异常

java.security.AccessControlException: access denied (java.net.SocketPermission 27.112.123.254:4444 connect,resolve)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:342)
    at java.security.AccessController.checkPermission(AccessController.java:553)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
    at java.net.Socket.connect(Socket.java:541)
    at java.net.Socket.connect(Socket.java:495)
    at java.net.Socket.<init>(Socket.java:392)
    at java.net.Socket.<init>(Socket.java:206)
    at sas.actionPerformed(sas.java:25)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
    at java.awt.Component.processMouseEvent(Component.java:6175)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:5940)
    at java.awt.Container.processEvent(Container.java:2105)
    at java.awt.Component.dispatchEventImpl(Component.java:4536)
    at java.awt.Container.dispatchEventImpl(Container.java:2163)
    at java.awt.Component.dispatchEvent(Component.java:4362)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
    at java.awt.Container.dispatchEventImpl(Container.java:2149)
    at java.awt.Component.dispatchEvent(Component.java:4362)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

Please help me guy's...!! 请帮我...

Is this started as an applet? 这是作为applet开始的吗? If so, you can only connect to the server from where the code originated unless you sign it. 如果是这样,除非您对代码进行签名,否则您只能连接到代码起源的服务器。

I think you just smacked headlong in to the Java SE platform security system. 我认为您只是全神贯注于Java SE平台安全系统。 Take a look at this information on the Java SE security model, specifically around the Permissions classes. 看看这个信息对Java SE安全模型,特别是围绕权限类。

The java.net.SocketPermission classes control what ports the VM can access outside of the local machine. java.net.SocketPermission类控制VM可以在本地计算机外部访问的端口。 These are usually controlled by a Policy file somewhere around the VM (look at the VM documentation to figure out where this is). 这些通常由VM周围某处的策略文件控制(请查看VM文档以了解其位置)。 You will need to modify the policy file to allow the VM to access other sockets. 您将需要修改策略文件以允许VM访问其他套接字。

It isn't intuitive - in fact, it's a royal pain - but it is designed to keep the VM from doing whatever it wants. 这不是直观的-实际上,这是一种皇家痛苦-但它的目的是防止VM执行其所需的任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM