| Author |
Just can't open serverSocket
|
Isaac Jones
Greenhorn
Joined: Jun 18, 2004
Posts: 25
|
|
Hi, I just can't get this to work. It never opens the ServerSocket (doesn't matter which port). It seems to me that it never gets in the try-function. What am i doing wrong? has anyone an idea? thanks for your answers. Here is the code:
|
 |
sander hautvast
Ranch Hand
Joined: Oct 18, 2002
Posts: 71
|
|
|
do you get an exception?
|
 |
sander hautvast
Ranch Hand
Joined: Oct 18, 2002
Posts: 71
|
|
just curious: why do you want to open a serversocket in a client (applet)? a "normal" configuraton would be a serversocket on the server (opened outside the applet) and applet clients connecting to it. are client and server on same host? If not check listening ports on the client. you just might see a listen state on the port you specified. or am i missing the point??
|
 |
Isaac Jones
Greenhorn
Joined: Jun 18, 2004
Posts: 25
|
|
|
no nothing. I've even put that part in a different function and called it from the function connect2server but it doesn't change anything. if no idea what the problem could be.
|
 |
Isaac Jones
Greenhorn
Joined: Jun 18, 2004
Posts: 25
|
|
|
well... i'm trying to program a messenger (thin-client). when you start the applet your information will be sent to the server (username, ip). the server should connect than back to the client so that you can transfer messages with other users later on.
|
 |
sander hautvast
Ranch Hand
Joined: Oct 18, 2002
Posts: 71
|
|
ok, have you checked that the applet is allowed to open ServerSockets? [ June 28, 2004: Message edited by: sander hautvast ]
|
 |
Isaac Jones
Greenhorn
Joined: Jun 18, 2004
Posts: 25
|
|
|
no i haven't. but that shouldn't be the problem because the applet is running on my machine (local).
|
 |
sander hautvast
Ranch Hand
Joined: Oct 18, 2002
Posts: 71
|
|
i don't think anything's wrong with your code. it works with me (i removed the connect to port 8051). using: this.getTextArea().append("Can't open socket\n"+e.getClass().getName()+":"+e.getMessage()); instead of this.getTextArea().append("Can't open socket\n"); should give you an exception. maybe the port is in use.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
Note that applets are prevented from opening server sockets by the default Java security policy in place in all web browsers and the Java plug-in. Changing this from the default is a very bad idea -- would you want the computers at your organization to download code over the network which could then set up a wares server/spam slave/whatever on every desktop in the company? It's reasonably safe to enable this capability based on digital signatures; this is a fairly large topic. Anyway, you don't need to have the applet open a server socket to be a chat client. No existing chat clients work this way. Sockets are full-duplex connections -- if a client opens a connection to a server, then the client can send data to the server, and the server can send data to the client.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Isaac Jones
Greenhorn
Joined: Jun 18, 2004
Posts: 25
|
|
ok, i see. this would explain why nothing happens when i call the function openServerSocket() in the applet. I understand how i can connect and send messages to the server. But how can the server pass the messages on to another client? When a client connects to the server for the first time, i send the clients username and ip to the server. this information is saved in a hashtable. do i even need this information? or how can i identify all those clients? since it's a messenger and not a chatroom i only want to pass the information on to one specific client. How would you realize that?
|
 |
 |
|
|
subject: Just can't open serverSocket
|
|
|