我写了下面的两个类,是想实C/S之间的通信.我要怎么设置类中的值,才能实现通信呢?我在运行SocketClient 时,出现java.net.ConnectException: Connection refused: connect的异常!请指教一下,小弟.
package urlsocket;
import java.net.*;
import java.io.*;
public class SocketClient {
Socket s=null;
DataInputStream instream=null;
DataOutputStream outstream=null;
public SocketClient() {
try{
init();
waitData();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
void init() throws Exception
{
s=new Socket( "192.168.0.102 ",8765);
instream=new DataInputStream(s.getInputStream());
outstream=new DataOutputStream(s.getOutputStream());
s.setSoTimeout(3000);
}
void waitData()
{
while(true)
{
try{
String str=instream.readUTF();
System.out.println( "Client accept: "+str);
str=Integer.toString(Integer.parseInt(str)+1);
outstream.writeUTF(str);
}catch(Exception e)
{
System.out.println(e.toString());
break;
}
}