Return to Snippet

Revision: 35836
at November 14, 2010 08:51 by mouseroot


Initial Code
import java.net.*;
import java.io.*;

class ....

 static String domain;
 static int port;
 static InetAddress addr;
 static BufferedReader in;
 static BufferedWriter out;
 static Socket sock;
 static String line;

public ....(String d,int p) {
        domain = d;
        port = p;
        try {
                addr = InetAddress.getByName(domain);
                sock = new Socket(addr,port);
                in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
                out =new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));

                }
            catch(Exception ee)
            {
              JOptionPane.showMessageDialog(null,"Constructor Error: " + ee);
            }

        }

//Data to Output to the socket
try {
out.write("Data to send");
out.flush();
}
catch(Exception ee)
{}

//read data from socket

try {
while((line = in.readline()) != null) 
{
System.out.println(line);
}
}catch(Exception e)
{}

Initial URL

                                

Initial Description
A simple implantation of sockets
input and output

Initial Title
Sockets in Java Input and Output

Initial Tags

                                

Initial Language
Java