编译通过了,但是在运行时出现下列错误,请高人指点:
java.net.ConnectException:Connection refused:connect
源文件:
import java.net.*;
import java.io.*;
class TcpTest
{
public static void main(String[] arg)
{
if(arg.length>0)
{ Procsure();}
else
Client();
}
public static void Procsure()
{
try
{
ServerSocket ss=new ServerSocket(6000);
Socket s=ss.accept();
OutputStream os=s.getOutputStream();
InputStream is=s.getInputStream();
os.write("hello!my name is fuqingjian".getBytes());
byte[] buf=new byte[100];
int len=is.read(buf);
System.out.println(new String(buf,0,len));
os.close();
is.close();
s.close();
ss.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void Client()
{
try
{
Socket s=new Socket(InetAddress.getByName(null),6000);
OutputStream os=s.getOutputStream();
InputStream is=s.getInputStream();
byte[] buf=new byte[100];
int len=is.read(buf);
System.out.println(new String(buf,0,len));
os.write("hello,this is client!".getBytes());
os.close();
is.close();
s.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}