????/**
???? * ??????????????????????????????????ó??????????????????
?????????????????????????
???? */
????package com.xushouwei;
????//??????????
????import java.net.*;
????import java.io.*;
????public class TServer
????{
???? public static void main(String[] args)
???? {
 ????//????ServerSocket??
 ????ServerSocket s=null;
 ????//????Socket??
 ????Socket s1;
 ????//???巢???????
 ????String sendString="??????????????...";
???? //?????????????????
 ????int s1lenth=sendString.length();
 ????//????OutputStream??
 ????OutputStream s1out;
 ????//????DataOutputStream??
 ????DataOutputStream dos;
 ????//???1314??????????
???? try
???? {
 ????//????ServerSocket??????????
 ????s=new ServerSocket(1314);
 ????} catch (Exception e)
???? {
 ????e.printStackTrace();
 ????}
???? //??????м????????????????????
???? while(true)
???? {
???? try
???? {
 ????//??????????????????
???? s1=s.accept();
 ????//?????socket?????????????????
 ????s1out=s1.getOutputStream();
???? dos=new DataOutputStream(s1out);
 ????//?????????
???? dos.writeUTF(sendString);
 ????//???????????????????Socket?????
 ????dos.close();
???? s1out.close();
 ????s1.close(); 
 ????} catch (Exception e)
 ????{
 ????e.printStackTrace();
 ????}
???? }
???? }
 
????}
 
????2.????????
????TCP/IP ??????????ó???????? Java ?????????? Socket ??????????????Socket ???????????????????????????????????????????????????
????Socket(InetAddress address??int port)
????Socket(InetAddress address??int port??Boolean stream)
????Socket(String host??int port)
????Socket(String host??int port?? InetAddress localAddr??int localPort)
???????У?address??host ?? port ??????????????? IP ??????????????????stream ?????? Socket ???????????? Socket??localAddr ?? localPort ????????????????????
???????????????????????????????????????????????????????????????
????/**
???? * ????????????????????????????????????????????????????????????????????????????
???? */
????package com.xushouwei;
????//??????????
????import java.net.*;
????import java.io.*;
????public class TClint
????{
???? public static void main(String[] args)
???? {
???? //????Socket??
 ????Socket s1;
 ????//????InputStream??
 ????InputStream s1In;
 ????//????DataInputStream??
 ????DataInputStream dis;
 ????try
 ????{
 ????//????1314??????
 ????s1=new Socket("127.0.0.1"??1314);
 ????//???socket?????????????????ж??????
 ????s1In=s1.getInputStream();
 ????dis=new DataInputStream(s1In);
 ????String st=new String(dis.readUTF());
 ????System.out.println(st);
 ????//?????????????????????socket????
 ????dis.close();
 ????s1In.close();
 ????s1.close();
 ????} catch (Exception e)
 ????{
 ????e.printStackTrace();
 ????}
 ????}
 
????}