public class Jclient {
public static void main(String[] args) {
Socket JavaSocket = null;
DataOutputStream os = null;
DataInputStream is =null;
try {
JavaSocket= new Socket("210.72.13.72",9734);
os = new DataOutputStream(JavaSocket.getOutputStream());
is = new DataInputStream(JavaSocket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host");
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to");
}
if (JavaSocket != null && os != null && is != null)
{
try {
String jcStr="this is Java 客户端 send string";
byte[] jcBytes =jcStr.getBytes();
os.write(jcBytes);//使用byte[]发送数据包
os.flush();
byte[] cbuf=new byte[8096];
is.read(cbuf);
String responseLine=new String(cbuf);
System.out.println("读取到的String是:"+responseLine);
os.close();
is.close();
JavaSocket.close();
} catch (UnknownHostException e) {
System.err.println("Trying to connect to unknown host: " + e);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
}
}
}
public static void main(String[] args) {
Socket JavaSocket = null;
DataOutputStream os = null;
DataInputStream is =null;
try {
JavaSocket= new Socket("210.72.13.72",9734);
os = new DataOutputStream(JavaSocket.getOutputStream());
is = new DataInputStream(JavaSocket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host");
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to");
}
if (JavaSocket != null && os != null && is != null)
{
try {
String jcStr="this is Java 客户端 send string";
byte[] jcBytes =jcStr.getBytes();
os.write(jcBytes);//使用byte[]发送数据包
os.flush();
byte[] cbuf=new byte[8096];
is.read(cbuf);
String responseLine=new String(cbuf);
System.out.println("读取到的String是:"+responseLine);
os.close();
is.close();
JavaSocket.close();
} catch (UnknownHostException e) {
System.err.println("Trying to connect to unknown host: " + e);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
}
}
}