本帖最后由 漪顿 于 2013-8-18 21:25 编辑
//客户端
package soncket;
import java.io.*;
import java.net.*;
public class Socket_1
{
public static void main(String[]args)throws Exception
{
Socket s=new Socket("192.168.1.3",10010);
OutputStream os=s.getOutputStream();
os.write("wolaile".getBytes());
s.close();
}
}
//服务端
package soncket;
import java.io.*;
import java.net.*;
public class ServerSocket_1
{
public static void main(String[]args)throws Exception
{
ServerSocket ss=new ServerSocket(10010);
Socket s=ss.accept();
String i=s.getInetAddress().getHostAddress();
System.out.println(i);
InputStream is=s.getInputStream();
byte[]by=new byte[1024];
int x=is.read(by);
System.out.println(new String(by,0,x));
s.close();
ss.close();
}
}
按照毕老师讲的做了一遍,怎么还是报错,这是哪的事呀?
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at soncket.Socket_1.main(Socket_1.java:8)
|