wood burning stoves 2.0*
The moose likes JSP and the fly likes need help on jsp, tcp/ip, socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "need help on jsp, tcp/ip, socket" Watch "need help on jsp, tcp/ip, socket" New topic
Author

need help on jsp, tcp/ip, socket

john can
Greenhorn

Joined: Jul 20, 2004
Posts: 19
guys,

guys, friends, i really need help on this.

say, i want to send something like [string],[string] thru tcp/ip(network) to another daemon which listen to port 10000, and the daemon is in c language.

n e 1 please guide me..
p/s : possible, please include a tag lib/ full source code. please..

thanks
-john
[ January 13, 2005: Message edited by: Bear Bibeault ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You need to look at the java.net package. This gives you the classes you need for network communication. That the daemon process is written in C doesn't really matter if you are communicating with it via TCP/IP packets.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
john can
Greenhorn

Joined: Jul 20, 2004
Posts: 19
n e luck on source codes ? or tag lib ?
thanks..
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
this has nothing to do with JSP... As John said, look at network programming. It's a very broad subject, there's tutorials and books about it which you should read.


42
john can
Greenhorn

Joined: Jul 20, 2004
Posts: 19
sorry din made clear earlier..
what i do meant is, the jsp page will take the input from user, then pass to the server..
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by john can:
sorry din made clear earlier..
what i do meant is, the jsp page will take the input from user, then pass to the server..


But again i assume you are comfortable with the JSP part all you want to do is to send the user input via TCP/IP. So, its about the java networking.

your handler classes would do the networking work not the JSP. A big picture can be,

JSP ---> Servlet ----> Handler Class ----> send info via TCP/IP

you haven't specified what response you want so i didn't show the way back.

cheers.
john can
Greenhorn

Joined: Jul 20, 2004
Posts: 19
means need to hard codded on the servlet and handler class ?
n e resources avaliable ?
-thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No there is no need to hard code the values in the servlet.
If you need help with something specific, you will need to ask a specific question.

Something along the lines of:
How do set initialization parameters in a servlet?
Or
How do I parse parameters passed to a servlet from a web page form?

If you don't understand servlet programming a forum is not the best place to start. Start by looking for Servlet/JSP tutorials or pick up a book. The same goes with tcp/ip programming. Paul told you what Java package the sockets libraries are in. That should be enough to get you running with Google.

There probably aren't a whole lot of examples of direct socket programming done from within a servlet, so if your looking for a pre-written example, you probably won't find one too fast.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
john can
Greenhorn

Joined: Jul 20, 2004
Posts: 19
ok guys.. thanks for your help.. tht i am able to move this far.

well, referring to http://www.servletsuite.com/servlets/sockettag.htm

i have downloaded the taglib.it works fine.but 1 thing..

-----------------------------------------------------------------
xxx.jsp

....
....
<%@ taglib uri="taglib.tld" prefix="t" %>

<t:readSocket host="127.0.0.1" port="10000">Testing </t:readSocket> //line 1
<t:readSocket host="localhost" port="8080"></t:readSocket> //line 2
...
...

-----------------------------------------------------------------------
[line (1)] -> my prog receives the string..
myprog (daemon) will responce, and the responce will be printed directly at[line (2)]

ok.. let say, how can i make declaration, when to pass the string to a variable?
will it be something like ?

------------------------------------------------------------------------
<t:readSocket host="127.0.0.1" port="10000" id = "a"></t:readSocket>
<% System.out.println("Responce : " + a);
%>
------------------------------------------------------------------------
or
------------------------------------------------------------------------
in theoritical; { a = action[<t:readSocket host="127.0.0.1" port="10000" id = "a"></t:readSocket>] }, prints(a) ?


-john
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The point of taglibs is not to declare and work with variables directly in your JSPs.

The idea is to put the tag where you want it's output printed.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
Dont write code like that in JSP. Make a JavaBean that does the socket communication. The really important avantages include the ability to test the bean OUTSIDE the JSP environment. Much faster write-compile-test cycle time, much easier to write test conditions, much more portable to another project.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help on jsp, tcp/ip, socket