|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
SecurityExeptionEx?
I am making a java chat and I get
securityExeptionEx:cannot access ip : port ip and port are my ip and port here is code to connect client to the server Code:
try
{
socket = new Socket (host, Integer.parseInt (port));
InputStream ii = socket.getInputStream ();
OutputStream oo = socket.getOutputStream ();
i = new DataInputStream (new BufferedInputStream (ii));
o = new DataOutputStream (new BufferedOutputStream (oo));
o.writeUTF (nameInput);
o.flush ();
Outputs.appendText ("Connection established...\n");
}
catch (IOException ex)
{
ex.printStackTrace ();
}
and this is server code Code:
ServerSocket server = new ServerSocket(port);
while (true)
{
Socket client = server.accept();
System.out.println("Accepted from " + client.getInetAddress());
handler c = new handler(client);
c.start();
System.out.println("Users connected: " + String.valueOf(c.handlers.size()+1));
}
When I execute client.java in editor it connects and works fine but when I open client.html it gives that error Why does that happen and how to fix it?
__________________
Thank you for any help. |
|
#2
|
|||
|
|||
|
I assume you are trying to make an applet that does this? If so, applets can only connect to the "server" they were served from. I also further assume that you are not running an actual web server off your machine and are merely double clicking the html file to view it? I do not know what info the applet will have as its originating server when you just double click on it. This is probably the problem.
If this is all true, as long as your server (the serversocket code) and the web server that serves your applet up are on the same box when deployed, my guess is that your code will work. If you do not have a web server handy, download apache and install it. They have a binary for windows that you can install fairly quickly. You should then be able to access the html file through a running apache on your machine and run the serversocket code and I bet it will work. Hope that all made sense and it helps. gl |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > SecurityExeptionEx? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|