telnet
to the time of day service
2.tucotuco.cs.indiana.edu% telnet school.cs.indiana.edu 13 Trying 129.79.252.119... Connected to school.cs.indiana.edu. Escape character is '^]'. Thu Oct 1 12:08:51 1998 Connection closed by foreign host.
telnet
to your web server
2.1 write your own clienttucotuco.cs.indiana.edu% pwd /nfs/paca/home/user2/dgerman/httpd/htdocs tucotuco.cs.indiana.edu% vi myfile tucotuco.cs.indiana.edu% cat myfile ***( this is my test )*** tucotuco.cs.indiana.edu% pwd /nfs/paca/home/user2/dgerman/httpd/htdocs tucotuco.cs.indiana.edu% [...] school.cs.indiana.edu%telnet tucotuco.cs.indiana.edu 19800 Trying 129.79.251.110... Connected to tucotuco.cs.indiana.edu. Escape character is '^]'. GET /myfile HTTP/1.0 HTTP/1.1 200 OK Date: Thu, 01 Oct 1998 17:18:06 GMT Server: Apache/1.3.1 (Unix) Last-Modified: Thu, 01 Oct 1998 17:16:57 GMT ETag: "4bccb-20-3613b909" Accept-Ranges: bytes Content-Length: 32 Connection: close Content-Type: text/plain ***( this is my test )*** Connection closed by foreign host. school.cs.indiana.edu%
2.2 write your own servertucotuco.cs.indiana.edu% vi myClient.java tucotuco.cs.indiana.edu% cat myClient.java import java.io.*; import java.net.*; class myClient { public static void main (String[] args) { try { Socket t = new Socket("tucotuco.cs.indiana.edu", 13); DataInputStream is = new DataInputStream(t.getInputStream()); boolean more = true; while (more) { String str = is.readLine(); if (str == null) more = false; else System.out.println(str); } } catch (IOException e) { System.out.println("Error: " + e); } } } tucotuco.cs.indiana.edu% javac myClient.java Note: myClient.java uses a deprecated API. Recompile with "-deprecation" for details. 1 warning tucotuco.cs.indiana.edu% java myClient Thu Oct 1 12:20:33 1998 ÿ tucotuco.cs.indiana.edu% date Thu Oct 1 12:20:37 EST 1998 tucotuco.cs.indiana.edu% date; java myClient; date Thu Oct 1 12:20:50 EST 1998 Thu Oct 1 12:20:54 1998 ÿ Thu Oct 1 12:20:54 EST 1998 tucotuco.cs.indiana.edu%
tucotuco.cs.indiana.edu% vi myNewClient.java tucotuco.cs.indiana.edu% diff myClient.java myNewClient.java 4c4 < class myClient { --- > class myNewClient { 7c7 < Socket t = new Socket("tucotuco.cs.indiana.edu", 13); --- > Socket t = new Socket("tucotuco.cs.indiana.edu", Integer.parseInt(args[0])); tucotuco.cs.indiana.edu% java myNewClient 13 Thu Oct 1 12:42:19 1998 ÿ tucotuco.cs.indiana.edu%
3.tucotuco.cs.indiana.edu% vi myServer.java tucotuco.cs.indiana.edu% cat myServer.java import java.io.*; import java.net.*; class myServer { public static void main (String[] args) { try { ServerSocket s = new ServerSocket(29800); Socket incoming = s.accept(); DataInputStream in = new DataInputStream(incoming.getInputStream()); PrintStream out = new PrintStream(incoming.getOutputStream()); out.println("Hello! Enter BYE to exit.\r"); boolean done = false; while (! done) { String str = in.readLine(); if (str == null) done = true; else { out.println("Echo: " + str + "\r"); if (str.trim().equals("BYE")) done = true; } } incoming.close(); } catch (Exception e) { System.out.println(e); } } } tucotuco.cs.indiana.edu% javac myServer.java Note: myServer.java uses a deprecated API. Recompile with "-deprecation" for details. 1 warning tucotuco.cs.indiana.edu% java myServer ... in the meantime on school... school.cs.indiana.edu%telnet tucotuco.cs.indiana.edu 29800 Trying 129.79.251.110... Connected to tucotuco.cs.indiana.edu. Escape character is '^]'. Hello! Enter BYE to exit. My name is Adrian Echo: My name is Adrian I see... Echo: I see... You too Echo: You too I mean you, not I. Echo: I mean you, not I. OK, BYE Echo: OK, BYE BYE Echo: BYE Connection closed by foreign host.
POST
to a script of
yours with telnet
We have a script that can be used to mail a comment to the webmaster.
3.1 the script
3.2 the experimenttucotuco.cs.indiana.edu% pwd /nfs/paca/home/user2/dgerman/httpd/cgi-bin/lecture9 tucotuco.cs.indiana.edu% ls -l *.pl -rwx------ 1 dgerman students 265 Sep 27 23:49 mailto.pl tucotuco.cs.indiana.edu% cat mailto.pl #!/usr/bin/perl print qq{Content-type: text/plain\n\n}; if ($ENV{'REQUEST_METHOD'} eq 'POST' && open(MAIL, "| mail dgerman\@indiana.edu")) { while (<STDIN>) { print MAIL; } close(MAIL); print "Mailto.pl"; } else { print "Error"; } tucotuco.cs.indiana.edu%
From school:
4. the feedback appletschool.cs.indiana.edu%telnet tucotuco.cs.indiana.edu 19800 Trying 129.79.251.110... Connected to tucotuco.cs.indiana.edu. Escape character is '^]'. POST /cgi-bin/lecture9/mailto.pl HTTP/1.0 Content-type: application/octet-stream Content-length: 10 Greetings! HTTP/1.1 200 OK Date: Thu, 01 Oct 1998 18:03:22 GMT Server: Apache/1.3.1 (Unix) Connection: close Content-Type: text/plain Mailto.plConnection closed by foreign host. school.cs.indiana.edu%
It's a combination of three things:
tucotuco.cs.indiana.edu% pwd /nfs/paca/home/user2/dgerman/httpd/htdocs/applets/feedback tucotuco.cs.indiana.edu% ls -l *.html -rw------- 1 dgerman students 133 Sep 27 23:29 Feedback.html tucotuco.cs.indiana.edu% cat Feedback.html <html> <head> <title> Feedback </title> </head> <body> <applet code=Feedback.class width=400 height=400> </applet> </body> </html> tucotuco.cs.indiana.edu%
tucotuco.cs.indiana.edu% pwd; ls -l *.java *.class /nfs/paca/home/user2/dgerman/httpd/htdocs/applets/feedback -rw-r--r-- 1 dgerman students 2841 Sep 28 00:11 Feedback.class -rw------- 1 dgerman students 1787 Sep 28 00:10 Feedback.java tucotuco.cs.indiana.edu%
tucotuco.cs.indiana.edu% pwd /nfs/paca/home/user2/dgerman/httpd/cgi-bin/lecture9 tucotuco.cs.indiana.edu% ls -l mailto.pl -rwx------ 1 dgerman students 265 Sep 27 23:49 mailto.pl tucotuco.cs.indiana.edu%For feedback to be collected a user needs to connect to:
http://tucotuco.cs.indiana.edu:19800/applets/feedback/Feedback.htmltype in the name and comment and then push the 'Send Comments' button.
The message will be sent to mailto.pl
and mailed to the webmaster by it.
Here's the code of Feedback.java
:
import java.awt.*; import java.applet.*; import java.net.*; import java.io.*; public class Feedback extends Applet { private TextField nameField = new TextField("", 20); private TextArea commentsField = new TextArea(5, 45); public void init() { add(new Label("Name")); add(nameField); add(new Label("Comments")); add(commentsField); add(new Button("Send Comments")); } public boolean action(Event evt, Object arg) { if (arg.equals("Send Comments")) { String data = nameField.getText() + "\n" + commentsField.getText() + "\n\n"; mailComments(data); goodBye(); } return super.action(evt, arg); } public void goodBye() { this.removeAll(); Graphics g = this.getGraphics(); g.drawString("Thanks", 5, 20); stop(); } public void mailComments(String sdata) { String home = "tucotuco.cs.indiana.edu"; String script = "/cgi-bin/lecture9/mailto.pl"; int port = 19800; Socket s = null; String rdata = ""; try { s = new Socket(home, port); DataOutputStream os = new DataOutputStream(s.getOutputStream()); DataInputStream is = new DataInputStream (s.getInputStream()); os.writeBytes("POST " + script + " HTTP/1.0\r\n" + "Content-type: application/octet-stream\r\n" + "Content-length: " + sdata.length() + "\r\n\r\n"); os.writeBytes(sdata); String line; while ((line = is.readLine()) != null) rdata += line + " "; showStatus(rdata); is.close(); os.close(); } catch (Exception e1) { showStatus("Error: " + e1); if (s != null) try { s.close(); } catch (IOException e2) { } } } }