[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Missing post? - see this post about spam for more information.
making a guestbook..  XML
Forum Index » J2EE Application Development
Author Message
shadow

Newbie
[Avatar]

Joined: 12/01/2005 09:15:08
Messages: 5
Offline

hi I have made a simple guestbook-like program the logic goes like this:

-you connect to it (using for example telnet - microsoft..)
-it asks you wether you want to post a message or read the messages.
-if you select post a message, it first save the data in an array then it, writes a message#.txt file, it also writes a nummessage.txt file.
[message#.txt=while # is the current message number, and all the message data is saved here]
[nummessage.txt=saves an int with the current number(see when it reads message to know why)]
-if you select read messages, then it reads the nummessage.txt file and see how many messages there are, after getting that number it uses that number as the limit to a loop and it reads "message"+i+".txt" files. then sends the messages to the telnet client.

now this works perfectly but in localserver, I was wondering if I somehow could use this online the way it works? or would I have to modify everything just wondering.
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 884
Location: Superior, CO, USA
Offline

Besides possible security issues I don't see why you couldn't put this online. Anytime you have something listening on a public port on a public machine you do need to be careful.

But based on what you've said it sounds like it will work fine on the internet.

This message was edited 1 time. Last update was at 12/01/2005 09:43:35


Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
shadow

Newbie
[Avatar]

Joined: 12/01/2005 09:15:08
Messages: 5
Offline

stdunbar wrote:Besides possible security issues I don't see why you couldn't put this online. Anytime you have something listening on a public port on a public machine you do need to be careful.

But based on what you've said it sounds like it will work fine on the internet.

oh ok thanks for clarifying that, also how do I know if the program will be running all the time in order for anyone to post/read messages? is this something to do with the server it would be residing?

and one las thing, I'm kind of new to this networking and sockets logic and this is the first time I dive into this I'm not that sure how would it work online, since in the localhost I first need to run the program and then I can connect to it through it with telnet...how would it be if it is online?

thanks again.
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 884
Location: Superior, CO, USA
Offline

shadow wrote:oh ok thanks for clarifying that, also how do I know if the program will be running all the time in order for anyone to post/read messages? is this something to do with the server it would be residing?


This part will be an O/S specific thing. Both Unix and Windows allow you to start processes on reboot of the machine. If the program has a tendency to crash (not that yours would of course, but code from other people sometimes does ) there are different ways to keep the process running depending on the O/S.

shadow wrote:and one las thing, I'm kind of new to this networking and sockets logic and this is the first time I dive into this I'm not that sure how would it work online, since in the localhost I first need to run the program and then I can connect to it through it with telnet...how would it be if it is online?


Pretty much the same way. Assuming that your program wasn't running you'd log into a remote machine somewhere using maybe ssh or telnet. Then you'd start up your program. Once it was running you'd be able to connect to it through either the IP address of the host or, depending on your setup, a name like shadow.somehostname.com. So instead of something like:



you'd do:


Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
shadow

Newbie
[Avatar]

Joined: 12/01/2005 09:15:08
Messages: 5
Offline

stdunbar wrote:
shadow wrote:oh ok thanks for clarifying that, also how do I know if the program will be running all the time in order for anyone to post/read messages? is this something to do with the server it would be residing?


This part will be an O/S specific thing. Both Unix and Windows allow you to start processes on reboot of the machine. If the program has a tendency to crash (not that yours would of course, but code from other people sometimes does ) there are different ways to keep the process running depending on the O/S.

shadow wrote:and one las thing, I'm kind of new to this networking and sockets logic and this is the first time I dive into this I'm not that sure how would it work online, since in the localhost I first need to run the program and then I can connect to it through it with telnet...how would it be if it is online?


Pretty much the same way. Assuming that your program wasn't running you'd log into a remote machine somewhere using maybe ssh or telnet. Then you'd start up your program. Once it was running you'd be able to connect to it through either the IP address of the host or, depending on your setup, a name like shadow.somehostname.com. So instead of something like:



you'd do:




:o so first I would connect to server and tell it to start the guestbook, then I would connect to it..right?
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 884
Location: Superior, CO, USA
Offline

That sounds correct. If you can just leave it running (for example, put the process in the background in a Unix environment) you should only have to start it once.

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
shadow

Newbie
[Avatar]

Joined: 12/01/2005 09:15:08
Messages: 5
Offline

stdunbar wrote:That sounds correct. If you can just leave it running (for example, put the process in the background in a Unix environment) you should only have to start it once.

oh I could modify the code a bit then because I always make the progam end after the user post/read a message, how would I close the connection with the current user and yet still have the program running for the next user?
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 884
Location: Superior, CO, USA
Offline

It would help to see your code some but generally you have a ServerSocket that sits and waits in accept(). Once this method returns you have a Socket to communicate over. In many systems you spawn a thread to handle the Socket that was accept()'d so that you can handle multiple clients at the same time.

When the client is done with a socket it will close it. On the server side you'll get some indication that the read failed. Depending on the data you're passing back and forth this might be that you get a null from a read or some other indication. You close that socket and, if your using threads, end that thread. The main thread continues to listen and accept() new connections.

This message was edited 1 time. Last update was at 12/01/2005 11:05:44


Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
shadow

Newbie
[Avatar]

Joined: 12/01/2005 09:15:08
Messages: 5
Offline

stdunbar wrote:It would help to see your code some but generally you have a ServerSocket that sits and waits in accept(). Once this method returns you have a Socket to communicate over. In many systems you spawn a thread to handle the Socket that was accept()'d so that you can handle multiple clients at the same time.

When the client is done with a socket it will close it. On the server side you'll get some indication that the read failed. Depending on the data you're passing back and forth this might be that you get a null from a read or some other indication. You close that socket and, if your using threads, end that thread. The main thread continues to listen and accept() new connections.

oh ok I'll try that thanks.
 
Forum Index » J2EE Application Development
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2012 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle