解决在DHCP环境下私自指定IP和私自搭建DHCP服务器的方法
2007-08-30 17:17
696 查看
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
public class PipedStream {
/*
* 目的:测试java管道流
* 设计思路: 两个内部类;继承Thread通过run()发送,接受信息
* 描述:本示例不仅阐述了java管道流,同时使用了java设计模式 Singleton(单例)
*/
//程序入口
public static void main(String[] args) {
//输出\输入管道流类对象;通过类方法单例获取
PipedOutputStream out=Sender.getOut();
PipedInputStream in=Receiver.getIn();
try{
//输入\输出管道流链接方法 connect()
in.connect(out);
}catch(IOException ioe){
ioe.printStackTrace();
}
//启动线程,用start()
new Sender().start();
new Receiver().start();
}
//通过管道流链接发送消息;使用单例必须声明静态内部类
static class Sender extends Thread{
private static PipedOutputStream out=null;
//单例返回管道对象
public static synchronized PipedOutputStream getOut(){
if(out==null){
out=new PipedOutputStream();
}
return out;
}
//发送消息
public void run() {
String mess="Hello Receiver;I'm Sender !\n";
try{
//注意:转成字节数组发送
out.write(mess.getBytes());
out.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}
//通过管道流链接接受消息;使用单例必须声明静态内部类
static class Receiver extends Thread{
private static PipedInputStream in=null;
//单例返回管道对象
public static synchronized PipedInputStream getIn(){
if(in==null){
in=new PipedInputStream();
}
return in;
}
//接受消息
public void run() {
//定义字节数组
byte[] byt=new byte[1024];
try{
//读取消息
int len=in.read(byt);
//生成新字符串
String mess=new String(byt, 0, len);
System.out.println("The Sender say:\n"+mess);
}catch(Exception e){
e.printStackTrace();
}
}
}
}
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
public class PipedStream {
/*
* 目的:测试java管道流
* 设计思路: 两个内部类;继承Thread通过run()发送,接受信息
* 描述:本示例不仅阐述了java管道流,同时使用了java设计模式 Singleton(单例)
*/
//程序入口
public static void main(String[] args) {
//输出\输入管道流类对象;通过类方法单例获取
PipedOutputStream out=Sender.getOut();
PipedInputStream in=Receiver.getIn();
try{
//输入\输出管道流链接方法 connect()
in.connect(out);
}catch(IOException ioe){
ioe.printStackTrace();
}
//启动线程,用start()
new Sender().start();
new Receiver().start();
}
//通过管道流链接发送消息;使用单例必须声明静态内部类
static class Sender extends Thread{
private static PipedOutputStream out=null;
//单例返回管道对象
public static synchronized PipedOutputStream getOut(){
if(out==null){
out=new PipedOutputStream();
}
return out;
}
//发送消息
public void run() {
String mess="Hello Receiver;I'm Sender !\n";
try{
//注意:转成字节数组发送
out.write(mess.getBytes());
out.close();
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}
//通过管道流链接接受消息;使用单例必须声明静态内部类
static class Receiver extends Thread{
private static PipedInputStream in=null;
//单例返回管道对象
public static synchronized PipedInputStream getIn(){
if(in==null){
in=new PipedInputStream();
}
return in;
}
//接受消息
public void run() {
//定义字节数组
byte[] byt=new byte[1024];
try{
//读取消息
int len=in.read(byt);
//生成新字符串
String mess=new String(byt, 0, len);
System.out.println("The Sender say:\n"+mess);
}catch(Exception e){
e.printStackTrace();
}
}
}
}
相关文章推荐
- 解决在DHCP环境下私自指定IP和私自搭建DHCP服务器的方法
- 解决在DHCP环境下私自指定IP和私自搭建DHCP服务器的方法
- 解决在DHCP环境下私自指定ip和私自搭建dhcp服务器的方法
- DHCP下私自指定IP和私自搭建DHCP
- DHCP下私自指定ip和私自搭建dhcp
- DHCP下私自指定ip和私自搭建dhcp
- 阿里云服务器ping不通解决办法(云服务器搭建完环境访问不了ip解决办法)
- LINUX系统服务器上搭建DHCP服务,实现两大基本功能:1,自动分配ip;2,手工指定ip
- $_SERVER['HTTP_HOST']在客户的环境里,取得的值总是程序所在的服务器在其局域网内的ip值解决方法
- $_SERVER['HTTP_HOST']在客户的环境里,取得的值总是程序所在的服务器在其局域网内的ip值解决方法
- 如何使用mysql(lamp)分离环境搭建dedecms织梦网站及apache服务器常见的403http状态码及其解决方法
- VM 安装Linux虚拟服务器:环境搭建遇到:《Linux “ifconfig”看不到inet address》问题--解决土方法
- DHCP下私自指定ip和私自搭建dhcp
- [环境搭建]-Web Api搭建到IIS服务器后PUT请求返回HTTP Error 405.0 - Method Not Allowed 解决方法 转摘:http://blog.csdn.net/qiujuer/article/details/23827531
- [环境搭建]-Web Api搭建到IIS服务器后PUT请求返回HTTP Error 405.0 - Method Not Allowed 解决方法
- unix网络编程各种TCP客户-服务器程序设计实例附环境搭建和编译方法(一)
- Linux搭建python环境中cx_Oracle模块安装遇到的问题与解决方法
- 【解决】linux云主机服务器添加IP两种方法
- Eclipse搭建android环境及Genymotion模拟器安装问题解决方法
- Android开发环境搭建及常见问题解决方法