Monthly Archives: November 2008

Classroom source code

One_java http://documents.scribd.com/ScribdViewer.swf?document_id=8472543&access_key=key-1c52q7uw4i0ymlr3jokm&page=1&version=1&viewMode=

New chapter and lab#4

We move on to chapter 3 and lab#4 has already started too.

UDP sockets programming

UDPEchoServer Java http://documents.scribd.com/ScribdViewer.swf?document_id=7953935&access_key=key-220d4x7p270vt20cm74d&page=1&version=1&viewMode=

Get your own at Scribd or explore others:

Third lab

Some programming will be required for the third lab.

TCP sockets programming

Here you can find a copy of the source code java files I wrote during last class.

This is the client.


import java.net.Socket;
import java.io.*;
import java.util.Scanner;

class TestTCP {
public static void main(String args[]) throws java.net.UnknownHostException, java.io.IOException , java.lang.InterruptedException{
Socket s = new Socket ( "www.upv.es", 80 );
// Thread.sleep(100000);
PrintWriter output = new PrintWriter( s.getOutputStream(), true);
output.println("GET / HTTP/1.0");
output.println("");
Scanner input = new Scanner( s.getInputStream());
while(true) System.out.println(input.nextLine());
}
}

And this is the server code:


import java.net.*;
import java.io.*;
import java.util.Scanner;

class Server {

public static void main(String args[]) throws IOException, InterruptedException{
ServerSocket ss = new ServerSocket(8080);
while(true) {
Socket s = ss.accept();
Scanner input = new Scanner( s.getInputStream());
PrintWriter output = new PrintWriter( s.getOutputStream(), true);
System.out.println(input.nextLine()); // reads a line from the socket (client)
output.println("Hello client!");
s.close();
}
}
}

Please note that I detailed during the class some DOs and DON’Ts that not necessarily show in my (quick and dirty) code.

First assignment is out


You have till December 1st to turn in this first assignment. You may need to have a look to SMTP protocol specification (RFC 821). Please note that this RFC has been obsoleted by newer versions. However, for the purpose of this assignment, the original version of SMTP specs are ok.