Solved

Starting a ServerSocket from an Applet

Posted on 1997-06-23
4
510 Views
Last Modified: 2008-03-06
I would like to support applet to applet communication
without having to start a server socket by hand (from the command line).
I really would like to start the server socket from an applet, and if at all possible I would even like the server socket's life to be independent from the applet's.
Is this in any way possible.
I was thinking of writing a server-side application to support the server socket, and let the applet create the application through a call to the server (Our Oracle WebServer supports server-side applications rather than server-side applets).
However, the application would never return!
I could keep the applet from hanging up by using a separate thread, though I'm afraid the application will stop as soon as the applet dies.
I want this socket server to serve the communication between many applets/people. I would like to end the server only when all users have stopped listening.
The only other solution I can think of is to create a separate server for each person, but that would really be overkill.
0
Comment
Question by:stouffs
  • 2
4 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1221960
There is a couple of solutions I can think of:

1.- URLConnection allows you to post/send to a CGI. The CGI could be a program (or shell script) that launces your server.

2.- You could use servlets if your using JDK1.1+

Which soloution sould work better for you?
0
 

Author Comment

by:stouffs
ID: 1221961
I would like to use your first solution, I can't use JDK1.1 yet.
The CGI program is a java application in my case.

0
 
LVL 2

Accepted Solution

by:
Philippe earned 120 total points
ID: 1221962

Stouffs,

what you want, is very similar to a chat server. There is an article on chat servers currently on webmonkey:

 http://www.hotwired.com/webmonkey/code/

If you use a cgi then every applet will execute the cgi once. Cgi are good for request-response type of applications. It seems you want the applets to exchange data or to get updates as long as they are connected. You also you want serveral applets to connect to the server at the same time. In that case it is better to write a server which will be listenning on a given port for incomming connections from applets. The proper way to start a server in that case is to always run it (eg start it at boot time).

 hope this helps,

   Philippe

0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1221963
You will probably wnat to look at:

http://www.inf.uni-hohenheim.de/top/java/tutorial/networking/urls/readingWriting.html

which has somewhat detailed information on how to send a post to a CGI from Java.

As long as the program you call deos not end, it will remain active.

As to the invocation itself. Its realy implementation specific. My advise would be to call a program that forks and spawns your server, and then ends, in order to release the connection resoources needed to call the CGI. The advantage of this is taht you can return a value indicating success/failure via stdout (standard CGI output).
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 52
JAVA API design with micro service cloud in mind 1 75
Java basic valueOf question 1 32
Java Eclipse Loop 3 28
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question