我的Socket哪里出错了?急急急急!!!
为什么我在运行时,会没有反应??好像出现死锁了!客户端:
import *;
import *;
class Client
{
Socket S;
BufferedReader BR;
PrintWriter BW;
InputStream IS;
OutputStream OS;
public void put()
{
try
{
Socket S=new Socket(InetAddress.getByName(null),6000);
IS=S.getInputStream();
OS=S.getOutputStream();
BR=new BufferedReader(new InputStreamReader(IS));
BW=new PrintWriter(OS);
BW.print("Hello");
System.out.println(BR.readLine());
BR.close();
BW.close();
IS.close();
OS.close();
S.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
Client S1=new Client();
S1.put();
}
}
服务器段:
import *;
import *;
class Server
{
public void pet()
{
Socket So;
BufferedReader BR;
PrintWriter BW;
InputStream IS;
OutputStream OS;
try
{
ServerSocket ss=new ServerSocket(6000);
So=ss.accept();
IS=So.getInputStream();
OS=So.getOutputStream();
BR=new BufferedReader(new InputStreamReader(IS));
BW=new PrintWriter(OS);
BW.print("Welcome to here!!");
System.out.print(BR.readLine());
BR.close();
BW.close();
IS.close();
OS.close();
So.close();
ss.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
Server S1=new Server();
S1.pet();
}
}
[[it] 本帖最后由 Javapet 于 2008-3-26 14:07 编辑 [/it]]