Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaandrotest;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.net.*;
- import java.util.Date;
- /**
- *
- * @author bennet.hentschel
- */
- public class Client {
- public static void main(String args[]) throws IOException, ClassNotFoundException {
- try {
- InetAddress addr = InetAddress.getLocalHost();
- int port = 80;
- SocketAddress sockaddr = new InetSocketAddress(addr, port);
- Socket sock = new Socket();
- int timeoutMs = 2000; // 2 seconds
- sock.connect(sockaddr, timeoutMs);
- System.out.println("connected");
- sock.getInputStream();
- InputStream in = sock.getInputStream();
- ObjectInputStream s = new ObjectInputStream(in);
- Date date = (Date) s.readObject();
- System.out.println("out: " + date.toString());
- } catch (UnknownHostException e) {
- } catch (SocketTimeoutException e) {
- } catch (IOException e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment