Socket/HTTP communication

Hello everybody. I am developing an instant-messaging program in JAVA (sort of like AIM) as a fun-project because I have nothing better to do in school :D

I have the program currently written in a LAN setup (where any client computers on the network connect to a certain server port on another computer on the network using its IP). But, of course, this program cannot be accessed from outside my school network. So I would like to put my "server" into a WWW address. Is this possible?

For example, I pretend I have a website (let's say http://www.something.com/mypage.html) that I want to act as the "server" for my application. Is there any way I can run a servlet (?) on my home computer that processes any information that is sent to that web address (URLConnection?) without having to completely rewrite my program? For example, if a client sends a communication message to /mypage.html can my "server" program process that information and send a message back (using sockets).

What I would like to do (although I am pretty sure it is much more complicated than this) is to just create a ServerSocket that is bound to a specific web address.

Notice that I do not need strict HTTP get/put/etc. requests (as I already have a full communication-scheme set up). In fact, I don't think an HTTP scheme would work because I would have to keep track of which computer is sending what to who, and as HTTP does not seem to keep track of its clients I would have to add even more parameters in each communication message I send to/from the server.

Lost? I'm trying my best to be as clear as possible here...

Anyway, I have searched the web and forums and all solutions deal with database information and strict HTTP processing, where I already have a program that does all the processing for me (I just want to somehow put a link between my app and the www).

I thought I might also mention that I am completely new to HTTP and HTML (as you may have probably guessed).

Thanks for your time and concern

Alex

[2062 byte] By [aRyan316a] at [2007-10-3 4:36:33]
# 1
Applet is often used, as client end, for your type of hobby project.Servlet would do also but I'd prefer applet for its simplicity -- server end should be much simpler than using servlets.Have fun!
hiwaa at 2007-7-14 22:40:14 > top of Java-index,Core,Core APIs...
# 2

You will have to do rewrite up to some extend if you are using HTTP. Becouse of two reasons.

1. Unlike sockets in HTTP you dont have a continious connection with your server component. Whenever the there is datato be transfered the clients sends a request and the server responds.

2. Server cant independantly send data to the client. Server can send data to the client only as a response to a request of the client. So there is no stream. (So you will have to implement a virtual stream on your own)

And when using HTTP you have to stick to the valid HTTP request methods otherwise the server will just discard your requst becouse it is invalid.

I recommend you to follow the servlet tutorial and write some servlets before starting your HTTP based software. So you will get a good idear about the differences between servlets/URLConnection and the socket communication.

LRMKa at 2007-7-14 22:40:14 > top of Java-index,Core,Core APIs...
# 3

Hmm... that is bad news for me LRMK (as that was what I feared was going to happen)

Applets are not quite what I want because I already have the program written as a stand-alone application. My understanding is that an applet is simply displayed on a webpage and can send information to the web-page. Rather, I want my application to send/receive information from a specific URL (so the user does not have to go to that URL him/herself).

But what is this "virtual stream" we are talking about? I can easily get all connected client IPs (they can just send that as part of their "connection" request) along with anything else that I might need to possibly set up a Socket connection. But my understanding is that NetworkInterface allows IP addresses to only be valid if the target IP is part of the network. Is this on the right track or complete gibberish?

And another quick question: if I have an http web address, does that mean I *have* to communicate with it using HTTP/JSP? (that seems to be my understanding, but I'm not absolutely positive)

Thanks for the responses!

aRyan316a at 2007-7-14 22:40:15 > top of Java-index,Core,Core APIs...
# 4

Also, how would I set up the server-side of an HTTP connection? I have searched around, but people always suggest using Tomcat or similar, which has way too many features for my needs (plus it destroys my fun in writing one from scratch :D).

So which classes should I look like if I wanted to write a server/servlet/whatever its called that receives information from a request from a specific web address, then writes a reply back? The Servlet class has all the functionality I need except I can't find a way to write a Servlet that receives from, let's say, http://www.something.com/mypage.html .

Am I making any sense? Am I missing some big concept?

In fact, I think I am. Because I can't set up a program that receives and replies to anything sent to google.com. For obvious reasons. So how would I go about setting up an http server? I'm lost.

Sorry that I'm so stupid and clueless in this subject. Not even the tutorials can help me (as they always set up their servers on localhost through IPs).

aRyan316a at 2007-7-14 22:40:15 > top of Java-index,Core,Core APIs...
# 5
I think you can ignore LRMK's comments because applet can establish separate and independent socket communication(s) with the server from which the applet and its HTML page are dispatched.
hiwaa at 2007-7-14 22:40:15 > top of Java-index,Core,Core APIs...