Specifications

Sun Services
Java™ Programming Language
Module 15, slide 11 of 12
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Minimal TCP/IP Client
1 import java.net.*;
2 import java.io.*;
3
4 public class SimpleClient {
5
6 public static void main(String args[]) {
7
8 try {
9 // Open your connection to a server, at port 5432
10 // localhost used here
11 Socket s1 = new Socket("127.0.0.1", 5432);
12
13 // Get an input stream from the socket
14 InputStream is = s1.getInputStream();
15 // Decorate it with a "data" input stream
16 DataInputStream dis = new DataInputStream(is);