高手,您好:
小弟写了一个Java Socket通信的实验工程,客户端与服务器的类型阵列如下图:
![图片描述][1]
(服务器端)
![图片描述][2]
(客户端)
源代码如下:
[code=java]
import java.io.File;
import java.net.Socket;
import java.util.HashMap;
class NodeMyGod_Hand{
static SocketServer so = null;
static String mySysNum = "a1";
static SocketClient soo = null;
static SocketServer sso = null;
static HashMap<String,SocketClient> hmso = new HashMap<String,SocketClient>();
public static String N_PORT_SERVER = "localhost";
static String OurSalesCenter = "www.baidu.com";
static int myusernumth = 0;
static HashMap<String,Socket> hm = new HashMap<String,Socket>();
static int myprojectversion = 1;
static HashMap<String,String> lib0 = new HashMap<String,String>();
static HashMap<String,String> lib1 = new HashMap<String,String>();
static public HashMap<String,String> myuserIP = new HashMap<String,String>();
public static HashMap<String,String> myuserPlace = new HashMap<String,String>();
public static HashMap<String,String> myuserSysNum = new HashMap<String,String>();
public static HashMap<String,String> myuserUID = new HashMap<String,String>();
int myMemworknum = 1;
int log0 =1;
// String OurSysMarketagent = "fscom.taobao.com";
public static void main(String[] args){
try{
new NodeMyGod_Hand();
}catch(Exception e){
e.printStackTrace();
}
}
@SuppressWarnings("null")
public NodeMyGod_Hand(){
sso = new SocketServer(11093);
String MyGodWill = null;
lib0.put("0","A");
lib0.put("1","C");
lib0.put("2","F");
lib0.put("3","E");
lib0.put("4","M");
lib0.put("5","A");
lib0.put("6","U");
lib0.put("7","H");
lib0.put("8","X");
lib0.put("9","R");
lib1.put("A","0");
lib1.put("C","1");
lib1.put("F","2");
lib1.put("E","3");
lib1.put("M","4");
lib1.put("A","5");
lib1.put("U","6");
lib1.put("H","7");
lib1.put("X","8");
lib1.put("R","9");
System.out.println("115 "+sso);
String MyUserRole = "";
String MyUserNum = "";
SocketClient so = null;
try{
while(true){
log0 = 0;
// System.out.println("118 " +sso);
// System.out.println("120 "+sso);
String MyThreadName = "";
String MyObjIP = "";
String SocketInfo = "";
int projectversion = 0 ;
int sign = 0;
try{
// synchronized(sso){
Socket s2 = sso.nextSocket();
try {
MyGodWill = sso.read(s2);
System.out.println("MyGodWill===================="+MyGodWill);
String[] buffer = MyGodWill.split("龘");
sign = Integer.parseInt(buffer[0]);
SocketInfo = buffer[1];
projectversion = Integer.parseInt(buffer[2]);
if(NodeMyGod_Hand.myprojectversion<=projectversion){
MyUserNum = buffer[3];
MyUserRole = buffer[4];
MyObjIP = buffer[5];
MyThreadName = buffer[6];
hm.put(MyUserRole+MyUserNum, s2);
} }catch(Exception e){
e.printStackTrace();
log0 = 1;
}
// MyEnterThread = new MyEnterThread(MyGodWill);
// .run();
if(log0 ==0){
switch(sign){
case 0:
{
//本线程用于验证C端新登陆的用户客户端的合法性,合法,回写给客户端字符串“a1”,不合法,回写给客户端字符串“4d”。
System.out.println("+++++++++++++++++++++++++++++");
System.out.println("sso======="+sso);
System.out.println("s2========"+s2);
System.out.println("+++++++++++++++++++++++++++++");
System.out.println("case 0:");
//下面的第五个参数,sso,为系统接收C端数据中心登录信息的SocketServer类型的实例,它的类体中,含有Socket对象,在这里
//传给CopyOfConfirmMyPartner类型的构造方法第5个参数,实现数据回写。
//下面的第一个参数,为“主板编号丠用户客户端注册码丠用户客户端注册手机号码”格式的一个字符串,拿到下面的CopyOfConfirmMyPartner
//类型中参与计算,验证传来此数据的C端客户端的登录合法性。
System.out.println("MyUserNum+++++++++++++++++++++++++"+MyUserNum);
System.out.println("MyUserRole++++++++++++++++++++++++"+MyUserRole);
System.out.println("NodeMyGod_Hand.hm+++++++++++++++++++++++"+NodeMyGod_Hand.hm);
System.out.println("NodeMyGod_Hand.hm.get(MyUserRole+MyUserNum)+++++++++++++++++++++++"+NodeMyGod_Hand.hm.get(MyUserRole+MyUserNum));
CopyOfConfirmMyPartner m = new CopyOfConfirmMyPartner(SocketInfo,MyObjIP,MyUserRole,MyUserNum,NodeMyGod_Hand.hm.get(MyUserRole+MyUserNum));
m.start();
break;
}
}}}catch(Exception e){
e.printStackTrace();
}
}}catch(Exception e){
e.printStackTrace();
}
}}
[/code]
(服务器端主类代码)
[code=java]
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.concurrent.ArrayBlockingQueue;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class DRecv {
static String MyportSysNum = "a1";
static int mymorningmem = 0;
public static int mywindoWstate = 0;
static HashMap<String,Socket> socketlib = new HashMap<String,Socket>();
HashMap<String,SocketClient1st> hmlibsocket = new HashMap<String,SocketClient1st>();
static byte[] MemCodeGrade = new byte[2000];
static String URL = "";
static LinkedList<Integer> myinvalidatecode = new LinkedList<Integer>();
String mynowchatobjrole = "";
byte MyMemGrade = 0;
String mypartnerficia = "";
int MySysNeed = 0;
String myObjIP = "";
static LinkedList<String> ld = new LinkedList<String>();
static String[] MyMemSysNum = null;
static int lenhypercodenum = 0;
static int lenservicecodenum = 0;
static int lenregistercodenum = 0;
static int myCustomerServicecodenum = 0;
static int[] myinvalidatehypercode = new int[20000];
static LinkedList<Integer> mySysCustomerCode = new LinkedList<Integer>();
static LinkedList<Integer> myregistercode = new LinkedList<Integer>();
int log0 = 0;
static String S_PORT_SERVER = "127.0.0.1";
static String Sysinvalidatecode = "D:" + File.separator + "MyDoc"
+ File.separator + "Dport" + File.separator + "BeiJing"
+ File.separator + "myinvalidatecode.txt";
static SocketServer sso1 = null;
public static SocketClient socketso;
public static int myprojectversion = 1;
/**
* @param args
*/
public static void main(String[] args) {
try{
new DRecv();
}catch(Exception e){
e.printStackTrace();
}
}
public DRecv() {
S_PORT_SERVER = "127.0.0.1";
File file = new File(
"D:\\Program Files\\MyGodWillMyIdeal\\MyHandWill\\MyCredits.txt");
if (file.exists()) {
String MyInfo = "0";
try {
ReadTxt
.read("D:\\Program Files\\MyGodWillMyIdeal\\MyHandWill\\MyCredits.txt");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// ////System.out.println(
// " "+ReadTxt.logData.get(0));
int i = 0;
String MyUserRights = "";
try {
MyUserRights = ReadTxt.logData.get(0);
} catch (IndexOutOfBoundsException e) {
MyUserRights = "99999999999999";
}
char[] ch = MyUserRights.trim().toCharArray();
String MyPartnerMainBoardNum = MiscUtils.getMotherboardSN();
if (MyUserRights.equals("")) {
MyUserRights = "99999999999999";
}
ReadTxt.logData.clear();
try {
ReadTxt.read("D:\\MyDoc\\Dport\\MyUserMobilePhone.txt");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String myUserPhone = ReadTxt.logData.get(0);
String str0 = "0龘" + MyPartnerMainBoardNum + "丠" + MyUserRights.replace(" ", "")
+ "丠" + myUserPhone;
SocketClient1st so = new SocketClient1st(DRecv.S_PORT_SERVER, 11093);
hmlibsocket.put("1st", so);
// try {
// so.writeStr(str0, "DRecv");
// } catch (NullPointerException e) {
// new NoteAdministratorServerInfo();
// }哥哥,弟想在这一行向服务器发出登录请求,这里的“str0”是包含了主板编号,用户的手机号码和由此计算出的用户授权码的一个由这三个数据拼接到一起的一个字符串,str0。
WriteStr obj = new WriteStr(so.getS(),str0, "DRecv");
obj.start();
sso1 = new SocketServer(5696);
Socket sog = sso1.nextSocket();
socketso.setS(sog);
try {
MyInfo = sso1.read(sog);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________");
MyInfo = "a1丗www.baohuwan.com丗尊敬的系统客户端中心的用户,您们好!!我是系统的信息发布人,现在很荣幸地,面向亲爱的系统C端客户进行信息发布:“导夫”家庭教育系统已经全新改版至5.18版,希望亲爱的C端用户注意更新,祝您愉快!!再会!!";
try {//袁哥,上面第327行是写出的数据样例。“a1”表示校验成功,客户端可以登录,“www.baohuwan.com”表示推送给客户端显示的网站页面。这里的“推送话语”,是服务器端推送到客户端的“叮嘱语句”,每天都可能不一样。
//哥哥,弟觉得,这里的功能实现,就是在服务器端再写一个Socket连接,连接到客户端,写出数据,应该就行了吧?可是,弟在这边怎么写,都只能是“写出数据位置”,“报错儿”,搞不掂了。。想到了哥哥。
// MyInfo = sso1.read(sog);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
System.out.println("MyInfo " + MyInfo);
} catch (Exception e) {
// TODO Auto-generated catch block
}
System.out.println("MyInfo " + MyInfo);
try {
String[] buffer = MyInfo.split("丗");
System.out.println(buffer[0]);
if (buffer[0].equals("a1")) {
try {
startGetValue();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String URL = buffer[1];
String mypartnerficia = buffer[2];
String mynowchatobjrole = "N";
String myObjIP = "127.0.0.1";
byte MyMemGrade = 5;
int MySysNeed = 0;
this.mypartnerficia=mypartnerficia;
this.mynowchatobjrole = mynowchatobjrole;
this.myObjIP = myObjIP;
this.MyMemGrade = MyMemGrade;
this.MySysNeed = MySysNeed;
} else {
URL = buffer[1];
BareBonesBrowserLaunch.openURL(URL);
String myusercode = "";
try {
myusercode = so.readStr();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
} catch (Exception e) {
log0 = 1;
}
} else {
BareBonesBrowserLaunch.openURL(URL);
String mycode = "";
try {
SocketClient1st so = new SocketClient1st(DRecv.S_PORT_SERVER,
11089);
mycode = so.readStr();
} catch (IOException e) {
// TODO Auto-generated catch block
}
ReadTxt.logData.clear();
ReadTxt.readMemoryData(mycode);
}
System.exit(0);
}
public void startGetValue() throws Exception, ClassNotFoundException,
InstantiationException, IllegalAccessException,
UnsupportedLookAndFeelException {
ReadTxt.logData.clear();
try {
try {
ReadTxt.read(Sysinvalidatecode);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
lenhypercodenum = ReadTxt.logData.size();
if (!(ReadTxt.logData.get(0) == null)) {
for (int i = 0; i < lenhypercodenum; i++) {
byte[] buffer = new byte[200];
buffer = ReadTxt.logData.get(i).getBytes();
if (ReadTxt.logData.get(0).equals(" ")) {
ReadTxt.logData.add("204748364");
}
// ////"第"+i+"笔数据的字节数为"+buffer.length);
try {
myinvalidatehypercode[i] = Integer
.parseInt(ReadTxt.logData.get(i));
} catch (NumberFormatException e) {
}
}
}
} catch (IndexOutOfBoundsException e) {
}
new JLabel0(this.mypartnerficia);
BareBonesBrowserLaunch.openURL("www.baidu.com");
int i = 0;
while (true) {// 是有一定概率让通信成功的,从这一点来看:应该是线程间合作没有弄好造成的吧?是不是小弟加锁加的不漂亮?》
Thread.sleep(100000);
}
}
}
[/code]
(客户端主类)
[code=java]
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class CopyOfConfirmMyPartner extends Thread{
String LocalSocketInfo = "";
String MyUserMainboardNum = "";
String MyUserCode = "";
String MyObjIP = "";
String MyPartnerPhoneNum = "";
String MyUserRole = "";
String MyUserNum = "";
String myInfoPath = "D:\\MyDoc\\Nport\\MyInfotoDport.txt";
Socket so = null;
public CopyOfConfirmMyPartner(String SocketInfo,String IP,String myUserRole,String myUserNum,Socket s){
LocalSocketInfo = SocketInfo;
MyObjIP = IP;
MyUserRole = myUserRole;
MyUserNum = myUserNum;
System.out.println("s============"+s);
so = s;
}
public static void main(String[] args){
CopyOfConfirmMyPartner m = null;
try {
m = new CopyOfConfirmMyPartner("123490EN400015丠MMPUWUfuWXT^\b丠09518937182曌201406161509560","localhost","C","01",new Socket("localhost",10018));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m.start();
}
public void run(){
try{
String[] buffer = LocalSocketInfo.split("丠");
MyUserMainboardNum = buffer[0];
MyUserCode = buffer[0].substring(0,14).trim();
MyPartnerPhoneNum = buffer[1].substring(0,11)+"000";
char[] ch0 = MyUserMainboardNum.toCharArray();
char[] ch1 = MyUserCode.toCharArray();
char[] ch2 = MyPartnerPhoneNum.toCharArray();
int[] mych0 = new int[ch0.length];
int[] mych2 = new int[ch2.length];
int[] mych3 = new int[ch0.length];
for(int i = 0;i<ch0.length;i++){
mych0[i] = (int)ch0[i];
mych2[i] = (int)ch2[2];
}
for(int i=0;i<ch0.length;i++){
if(i%2==0)
mych3[i]=(int)ch0[i]+(int)ch2[i]+10;
if(i%3==0)
mych3[i]=(int)ch0[i]+(int)ch2[i]+18;
if(i%5==0){
mych3[i]=(int)ch0[i]+(int)ch2[i]-2;
}
else{
mych3[i]=mych0[i]+mych2[i]+9;
}
}
for(int i=0;i<ch0.length;i++){
ch1[i]=(char)mych3[i];
}
int j = 0;
if(MyUserCode.equals(new String(ch1)))
j=0;
else
j=1;
// for(int i=0;i<ch0.length;i++){
//// if(mych3[i]==mych1[i]){
// continue;
//// }else{
// j=1;
// break;
// }
// }
if(j==0){
System.out.println(MyObjIP);
System.out.println("truely");
try{
System.out.println("a1丗"+NodeMyGod_Hand.OurSalesCenter);
System.out.println(so);
Thread.sleep(5000);
synchronized(so){
//"a1丗"+NodeMyGod_Hand.OurSalesCenter, "ConfirmMyParter"
//so.writeStr1("1", MyUserNum, "ConfirmMyPartner", "0", "0", "a1");
String DportfuctNum = "1";
String mydportfuctNum = "0";
String mydportsubfuctNum = "0";
String mySocketData = "a1";
WriteStr obj = new WriteStr(so,DportfuctNum, MyUserNum, "ConfirmMyPartner",mydportfuctNum,mydportsubfuctNum, mySocketData);
obj.start();
System.out.println("a1丗"+NodeMyGod_Hand.OurSalesCenter);
}
}catch(Exception e){
e.printStackTrace();
}
}else{
System.out.println("false");
System.out.println(MyUserNum);
WriteStr obj = new WriteStr(so,"1", MyUserNum, "ConfirmMyPartner", "0", "0", "4d");
obj.start();
}
}catch(Exception e){
e.printStackTrace();
}}
}
[/code]
(服务器端主类代码下层验证客户端登录权限的类型)
[code=java]
import java.net.InetAddress;
import java.net.UnknownHostException;
public class GetMyUserIP {
static InetAddress ip;
public static String getMyIP() {
try {
ip = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
// TODO Auto-generated catch block
}// 得到本机的IP
String strip = ip.toString();
String[] strArr = strip.split("/");
return strArr[1];
}
}
[/code]
(服务器端与客户端获取服务器本地IP地址的类型)
[code=java]
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class ReadTxt {
static String MyKey = "CJCO008";
static ArrayList<String> logData = new ArrayList<String>();
static ArrayList<String> logData0 = new ArrayList<String>();
static String text = null;
public static void read(String filePath) {
try {
FileReader input = new FileReader(filePath);
BufferedReader br = new BufferedReader(input);
while ((text = br.readLine()) != null) {
logData.add(text);
}
br.close();
input.close();
} catch (FileNotFoundException e) {
System.out.println("ReadTxt第24行");
e.printStackTrace();
// new NoteUserSysInfo();
} catch (IOException e) {
}
}
public static void readCyrpt(String filePath) {
try {
FileReader input = new FileReader(filePath);
BufferedReader br = new BufferedReader(input);
while ((text = br.readLine()) != null) {
//// String text0 = Systemcrypt.HloveyRC4(text, MyKey);
// logData.add(text0);
}
br.close();
input.close();
} catch (IOException e) {
}
}
public static void readMemoryData(String data) {
//// String data0 = Systemcrypt.HloveyRC4(data, MyKey);
// logData.add(data0);
}
public static void readMemoryCryptData(String data) {
logData.add(data);
}
public static void readMemoryArrayData(String[] data) {
int len = data.length;
for (int i = 0; i < len; i++) {
logData.add(data[i]);
}
}
public static void readMemoryArrayCryptData(String[] data) {
int len = data.length;
for (int i = 0; i < len; i++) {
// String data0 = Systemcrypt.HloveyRC4(data[i], MyKey);
// logData.add(data0);
}
}
public static void read0(String path4th) {
// TODO Auto-generated method stub
try {
FileReader input = new FileReader(path4th);
BufferedReader br = new BufferedReader(input);
while ((text = br.readLine()) != null) {
logData0.add(text);
}
br.close();
input.close();
} catch (FileNotFoundException e) {
System.out.println("ReadTxt第24行");
e.printStackTrace();
// new NoteUserSysInfo();
} catch (IOException e) {
}
}
}[/code]
(服务器端与客户端读取本地txt文件中的数据进入内存的类型)
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
/**
* 剪切板工具类
*
* @author NeverChange
*
*/
public class SocketClient {
public Socket getS() {
return s;
}
public void setS(Socket s) {
this.s = s;
}
static Socket s;
private InputStream in;
private OutputStream out;
private BufferedInputStream inByte;
private OutputStream outByte;
private BufferedReader inStr;
private PrintWriter outStr;
public String MyObjIP = "";
private long size = 0;private ServerSocket ss = null;
private Map<Socket, BufferedReader> rm = new HashMap<Socket, BufferedReader>();
private Map<Socket, PrintWriter> wm = new HashMap<Socket, PrintWriter>();
String MyKey = "CJCO5888CJCO";
BufferedReader br = null;
PrintWriter pw = null;
public SocketClient(String ip, int port) {
try {
s = new Socket(ip, port);
if(port == 9911)//只要连接端口是9911的,我就在这停下,然后看代码的堆栈,就知道哪地方哥哥,堆栈怎么看,您能告诉弟吗?
{
//System.out.println("开始连接9911端口了,请注意");
}
//System.out.println(s);
in = s.getInputStream();
out = s.getOutputStream();
MyObjIP = ip;
inByte = new BufferedInputStream(in);
outByte = out;
inStr = new BufferedReader(new InputStreamReader(in));
outStr = new PrintWriter(new OutputStreamWriter(out));
} catch (Exception e) {
}
}
public String readStr() throws IOException {
if (null == (br = rm.get(s))) {
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
rm.put(s, br);
}
String str0 = br.readLine();
// str0 = Systemcrypt.Recovery(str0,"CJCO");
synchronized (this.in) {
String str = this.inStr.readLine();
// return str = Systemcrypt.Recovery(str,"CJCO");
return str;
}
}
public File readToFile(File file) throws IOException {
synchronized (this.in) {
FileOutputStream fos = new FileOutputStream(file);
byte[] temp = new byte[1024 * 8];
int count = 0;
while (-1 != (count = this.inByte.read(temp))) {
fos.write(temp, 0, count);
fos.flush();
}
fos.close();
return file;//跑接收端的TestSendInfo与发送端的Client.
}
}
public void writeFile(File file) {
synchronized (this.out) {
size = file.length();
this.noticeFileSize(size);
FileInputStream fis;
try {
fis = new FileInputStream(file);
byte[] temp = new byte[1024 * 8];
int count = 0;
while (-1 != (count = fis.read(temp))) {
this.outByte.write(temp, 0, count);
this.outByte.flush();
}
fis.close();
} catch (Exception e) {
}
// long progress = 0;
// while (size != (progress = getServerReceiveSize())) {
// //////"progress : " + (progress / (size / 100)) + "%");
// }
}
}
private void noticeFileSize(long l) {
String str = l + "";
int j = 19 - str.length();
for (int i = 0; i < j; i++) {
str = "0" + str;
}
this.writeByByte(str);
}
protected void writeByByte(String content) {
synchronized (this.out) {
try {
this.out.write(content.getBytes());
this.out.flush();
} catch (IOException e) {
}
}
}
private long getServerReceiveSize() {
synchronized (in) {
byte[] b = new byte[19];
try {
this.in.read(b);
} catch (IOException e) {
}
return Long.parseLong(new String(b));
}
}
public String getProgress() {
long l = this.getServerReceiveSize() / (size / 100);
if (100 == l) {
return null;
}
return l + " %";
}
public void getMyresourceBack() {
if (s != null) {
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (inStr != null) {
try {
inStr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (outStr != null) {
outStr.close();
}
}
public void writeStr(String str, String myThreadname, int myfuct,
Integer chatPartnerSerialMark) {
// TODO Auto-generated method stub
String myInfo = "str"+"丗"+myThreadname +"丗"+"1"+"丗"+chatPartnerSerialMark;
}
public void write(Socket s, String content) throws IOException {
if (null == (pw = wm.get(s))) {
pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
wm.put(s, pw);
}
// content = Systemcrypt.HloveyRC4(content, "CJCO");
pw.println(content);
pw.flush();
}
//用于C端面向Y节点的case 3分支,所做的写入方法,用于确认本Cport能够登陆,获取本地用户信息。
public void writeStr0(String myfuctnum,String myObjNum, String myThreadname) {
// TODO Auto-generated method stub
synchronized (this.out) {
String IP = "127.0.0.1";
String str = myfuctnum+"龖"+"a1"+"龖"+myObjNum+"龖"+"D"+"龖"+"Y"+"龖"+"褚彦明"+"丗"+"cjcjcjcjcocococo!!"+"丗"+"D"+"丗"+IP+"龖"+myThreadname;
outStr.println(str);//因为println默认会在每行的后面加上/r/n,所以不需要再重复加了,避免不必要的影响
outStr.flush();
}
}
//用于Y端点向D端写出数据时的调用方法:首先本数据先经过Y节点,Y节点在经过判断之后,把数据发向D节点。之后D节点接收数据。
public void writeStr1(String myfuctnum,String myObjNum, String myThreadname,String mydportfuct,String mydportsubfuct,String mySocketData) {
// TODO Auto-generated method stub
synchronized (this.out) {
String IP = "127.0.0.1";
String content0 = "";
myThreadname = "";
String str = myfuctnum+"龖"+"a1"+"龖"+myObjNum+"龖"+"D"+"龖"+"D" +"龖"+mydportfuct+"丗"+mydportsubfuct+"丗"+"C"+"丗"+"a1"+"丗"+mySocketData+"丗"+"D"+"丗"+"BeiJing"+"丗"+IP+"丗"+myThreadname+"龖"+myThreadname;
outStr.println(str);//因为println默认会在每行的后面加上/r/n,所以不需要再重复加了,避免不必要的影响
outStr.flush();
}
}
//用于完成Y向Sport写入数据,数据首先经过Yport,Yport经过判断,把数据写给Sport,代码如下。
public void writeStr2(String myfuctnum,String myObjNum, String myThreadname,String mysportfuct,String mySocketData) {
// TODO Auto-generated method stub
synchronized (this.out) {
String IP = "127.0.0.1";
myThreadname = "";
String str = myfuctnum+"龖"+"a1"+"龖"+myObjNum+"龖"+"D"+"龖"+"S" +"龖"+mysportfuct+"丗"+mySocketData+"丗"+"D"+"丗"+"S"+"丗"+"a1"+"丗"+IP+"丗"+myThreadname+"丗"+1+"龖"+myThreadname;
outStr.println(str);//因为println默认会在每行的后面加上/r/n,所以不需要再重复加了,避免不必要的影响
outStr.flush();
}
}
//本方法用于Yport2Cport的数据传输,本数据先经过Yport的节点,Yport做完判断后,将本方法所含的数据,发送到
//数据发出方想要到达的Cport节点上。
public void writeStr3(String myfuctnum,String myObjNum,String mycportfuct,String mySocketData,String myThreadname){
synchronized (this.out) {
String IP = "127.0.0.1";
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String ip=addr.getHostAddress().toString();
String AP = "a1"+"龖"+myObjNum+"龖"+"Y"+"龖"+"C"+"龖";
String CP = mycportfuct+"丗"+"9"+"丗"+mySocketData+"丗"+"Y"+"丗"+ip+"丗"+"SocketClient"+"龖"+myThreadname;
String str = myfuctnum + "龖" + AP +CP;
//str.replaceAll("", replacement)
synchronized(s){
outStr.println(str);//因为println默认会在每行的后面加上/r/n,所以不需要再重复加了,避免不必要的影响
}
// //////////System.out.println("=============================||||||||||||||||||||||||||||||||||||||||||||"+content+"丗"+IP+"丗"+MyThreadname);
outStr.flush();
}}
//由节点向N节点写出数据,数据首先经过Y节点,之后进入目标节点N。
public void writeStr4(String myfuctnum,String myObjNum, String myThreadname,String mydportfuct,String mydportsubfuct,String mySocketData) {
// TODO Auto-generated method stub
synchronized (this.out) {
String IP = "127.0.0.1";
myThreadname = "";
String str = myfuctnum+"龖"+mySocketData+"龖"+NRecv0.myprojectversion+"龖"+NRecv0.MyportSysNum+"龖"+"D" +"龖"+mydportfuct+"丠"+
mydportsubfuct+"丠"+"Y"+"丠"+"a1"+"丠"+mySocketData+"丠"+""+"丠"+"小区D节点运营商所在营业地址"+"丠"+IP+"丠"+myThreadname+"龖"+myThreadname;
outStr.println(str);//因为println默认会在每行的后面加上/r/n,所以不需要再重复加了,避免不必要的影响
outStr.flush();
}
}
public void ServerThread(Socket s){
try {
in = s.getInputStream();
out = s.getOutputStream();
inByte = new BufferedInputStream(in);
outByte = out;
inStr = new BufferedReader(new InputStreamReader(in));
outStr = new PrintWriter(new OutputStreamWriter(out));
} catch (Exception e) {
}
}
}
(客户端与服务器端进行Socket连接的Socket API类型)
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class SocketClient1st {
static int myprojectversion = 1;
public Socket getS() {
return s;
}
public void setS(Socket s) {
this.s = s;
}
private Socket s;
private InputStream in;
private OutputStream out;
private BufferedInputStream inByte;
private OutputStream outByte;
private BufferedReader inStr;
private PrintWriter outStr;
private long size = 0;
public SocketClient1st(String ip, int port) {
try {
s = new Socket(ip, port);
in = s.getInputStream();
out = s.getOutputStream();
inByte = new BufferedInputStream(in);
outByte = out;
inStr = new BufferedReader(new InputStreamReader(in));
outStr = new PrintWriter(new OutputStreamWriter(out));
} catch (Exception e) {
}
}
public String readStr() throws IOException {
synchronized (this.in) {
String str = this.inStr.readLine();
// str = Systemcrypt.Recovery(str, "CJCO");
return this.inStr.readLine();
}
}
public void writeStr2Obj(String myfuct,String myfirstCportNum, String mySecondCportNum,String MyUserNum,String MySocketInfo) throws NullPointerException{
if(this.out==null){
try {
// System.out.println(""myPort);
s = new Socket(Recv.Y_PORT_SERVER, 9911);
out = s.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
synchronized (this.out) {
String IP = GetMyUserIP.getMyIP();
//content = content.replaceAll("\n", "<br>");
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String ip=addr.getHostAddress().toString();
String AP = Recv.D_PORT_SERVER+"龖"+"Y"+"龖";
String CP = myfirstCportNum+"丗"+mySecondCportNum+"丗"+MySocketInfo+"丗"+"D"+"丗"+ip;
String str = myfuct + "龖" + AP + CP ;
//str.replaceAll("", replacement)
outStr.println(str);//因为println默认会在每行的后面加上/r/n,所以不需要再重复加了,避免不必要的影响
// //////////System.out.println("=============================||||||||||||||||||||||||||||||||||||||||||||"+content+"丗"+IP+"丗"+MyThreadname);
outStr.flush();
}
}
public void writeStr(String content, String MyThreadname) {
synchronized (this.out) {
String IP = GetMyUserIP.getMyIP();
content = content.replaceAll("\n", "<br>");
String str = content + "龘"+ myprojectversion + "龘" + DRecv.MyportSysNum + "龘" +"D"+ "龘"+IP+ "龘" + MyThreadname + "\r\n";
// str = Systemcrypt.HloveyRC4(str,"CJCO");
outStr.println(str);
// //////////System.out.println("=============================||||||||||||||||||||||||||||||||||||||||||||"+content+"丗"+IP+"丗"+MyThreadname);
outStr.flush();
}
}
public File readToFile(File file) throws IOException {
synchronized (this.in) {
FileOutputStream fos = new FileOutputStream(file);
byte[] temp = new byte[1024 * 8];
int count = 0;
while (-1 != (count = this.inByte.read(temp))) {
fos.write(temp, 0, count);
fos.flush();
}
fos.close();
return file;
}
}
public void writeFile(File file) {
synchronized (this.out) {
size = file.length();
this.noticeFileSize(size);
FileInputStream fis;
try {
fis = new FileInputStream(file);
byte[] temp = new byte[1024 * 8];
int count = 0;
while (-1 != (count = fis.read(temp))) {
this.outByte.write(temp, 0, count);
this.outByte.flush();
}
fis.close();
} catch (Exception e) {
}
// long progress = 0;
// while (size != (progress = getServerReceiveSize())) {
// //////"progress : " + (progress / (size / 100)) + "%");
// }
}
}
private void noticeFileSize(long l) {
String str = l + "";
int j = 19 - str.length();
for (int i = 0; i < j; i++) {
str = "0" + str;
}
this.writeByByte(str);
}
protected void writeByByte(String content) {
synchronized (this.out) {
try {
this.out.write(content.getBytes());
this.out.flush();
} catch (IOException e) {
}
}
}
private long getServerReceiveSize() {
synchronized (in) {
byte[] b = new byte[19];
try {
this.in.read(b);
} catch (IOException e) {
}
return Long.parseLong(new String(b));
}
}
public String getProgress() {
long l = this.getServerReceiveSize() / (size / 100);
if (100 == l) {
return null;
}
return l + " %";
}
public void getMyresourceBack() {
if (s != null) {
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (inStr != null) {
try {
inStr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
if (outStr != null) {
outStr.close();
}
}
}
(服务器端与客户端的Socket API之二)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
public class SocketServer {
private ServerSocket ss = null;
private Map<Socket, BufferedReader> rm = new HashMap<Socket, BufferedReader>();
private Map<Socket, PrintWriter> wm = new HashMap<Socket, PrintWriter>();
String MyKey = "CJCO5888CJCO";
BufferedReader br = null;
PrintWriter pw = null;
public SocketServer(int port) {
try {
ss = new ServerSocket(port);
} catch (IOException e) {
e.printStackTrace();
}
}
public Socket nextSocket() {
Socket s = null;
try {
s = ss.accept();
} catch (Exception e) {
}
System.out.println(" $$$$$$$$$$$$$$$$$ "+s);
return s;
}
public String read(Socket s) throws IOException {
if (null == (br = rm.get(s))) {
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
rm.put(s, br);
}
String str = br.readLine();
return str;
}
public void write(Socket s, String content) throws IOException {
if (null == (pw = wm.get(s))) {
pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
wm.put(s, pw);
}
pw.println(content);
pw.flush();
}
public void getMyresourceBack() {
if (pw != null) {
pw.close();
}
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
// TODO Auto-generated catch block
}
}
if (rm != null) {
rm.clear();
}
if (wm != null) {
wm.clear();
}
if (ss != null) {
try {
ss.close();
} catch (IOException e) {
e.printStackTrace();
// TODO Auto-generated catch block
}
}
}
}
(客户端与服务器的Socket API之三)
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
public class WriteStr extends Thread{//extends Thread表示当前对象是一个线程,听过调用start方法可以执行线程的run部分的代码
static Socket s = null;
PrintWriter out = null;
String str = null;
public WriteStr(Socket s,String myfuctnum,String myObjNum, String myThreadname){
this.s = s;
try {
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (this.out) {
String IP = GetMyUserIP.getMyIP();
this.str = myfuctnum+"龖"+"a1"+"龖"+myObjNum+"龖"+"D"+"龖"+"Y"+"龖"+MyJButtonLogin.MyUID+"丗"+MyJButtonLogin.MyPWD+"丗"+"D"+"丗"+IP+"龖"+myThreadname;
}
}
public WriteStr(Socket s,String chatInfo){
this.s = s;
try {
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.str=chatInfo;
}
//向N端点写出验证合法用户数据的写出方法。
public WriteStr(Socket s,String myfuctnum,String myObjNum,String myObjRole,String myUserNum,String myUserRole,String myThreadname,int i){
this.s = s;
try {
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String IP = GetMyUserIP.getMyIP();
String str = myfuctnum+"龘"+MyJButtonLogin.MyUID+"丗"+MyJButtonLogin.MyPWD+"丗"+"C"+"丗"+IP+"龘"+String.valueOf(DRecv.myprojectversion)+"龘"+DRecv.MyportSysNum+"龘"+"D"+"龘"+GetMyUserIP.getMyIP()+"龘"+myThreadname;
this.str = str;
}
public WriteStr(Socket s,String myfuctnum,String myObjNum, String myThreadname,String MainBoardNum,String MyUserRights,String myUserMobilePhone,long i){
this.s = s;
try {
System.out.println("out----------------"+out);
System.out.println("this.s----------------"+this.s);
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String IP = GetMyUserIP.getMyIP();
String str = myfuctnum+"龖"+MainBoardNum+"丠"+MyUserRights+"丠"+"myUserMobilePhone"+"丗"+IP+"龖"+GetCportSocket.myUserNum+"龖"+myObjNum+"龖"+"Y"+"龖"+"Y"+"龖"+myThreadname;
this.str = str;
}
public WriteStr(Socket s,String myfuctnum,String myObjNum, String myThreadname,String MainBoardNum,String MyUserRights,String myUserMobilePhone,double i){
this.s = s;
try {
System.out.println("out----------------"+out);
System.out.println("this.s----------------"+this.s);
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String IP = GetMyUserIP.getMyIP();
System.out.println("myUserNum====================="+GetCportSocket.myUserNum);
String str = myfuctnum+"龘"+MainBoardNum+"丠"+MyUserRights+"丠"+myUserMobilePhone+"丗"+IP+"龘"+String.valueOf(DRecv.myprojectversion)+"龘"+myObjNum+"龘"+"Y"+"龘"+"Y"+"龘"+myThreadname;
this.str = str;
}
public WriteStr(Socket s,String myfuctnum,String myObjNum, String myThreadname,String mysportfuct,String mySocketData){
this.s = s;
try {
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String IP = GetMyUserIP.getMyIP();
String str = myfuctnum+"龖"+GetCportSocket.myUserNum+"龖"+myObjNum+"龖"+"Y"+"龖"+"S" +"龖"+mysportfuct+"丗"+mySocketData+"丗"+"C"+"丗"+"S"+"丗"+GetCportSocket.myUserNum+"丗"+IP+"丗"+myThreadname+"丗"+1+"龖"+myThreadname;
this.str=str;
}
public WriteStr(Socket s,String myfuctnum,String myObjNum, String myThreadname,String mydportfuct,String mydportsubfuct,String mySocketData){
this.s = s;
try {
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String IP = GetMyUserIP.getMyIP();
String str = myfuctnum+"龖"+GetCportSocket.myUserNum+"龖"+myObjNum+"龖"+"Y"+"龖"+"D" +"龖"+mydportfuct+"丗"+mydportsubfuct+"丗"+"C"+"丗"+GetCportSocket.myUserNum+"丗"+mySocketData+"丗"+"C"+"丗"+"BeiJing"+"丗"+IP+"丗"+myThreadname+"龖"+myThreadname;
this.str=str;
}
public WriteStr(Socket s,String str, String myThreadname, int myfuct,
Integer chatPartnerSerialMark){
this.s = s;
try {
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String IP = GetMyUserIP.getMyIP();
String myInfo = "str"+"丗"+myThreadname +"丗"+"1"+"丗"+chatPartnerSerialMark;
this.str=myInfo;
}
public WriteStr(Socket s,String content, String MyThreadname){
this.s = s;
try {
out = new PrintWriter(this.s.getOutputStream());
//还有这里必须使用PrintWriter来完成客户端和服务器段的通信.就改了这两个地方.恩师,第一个修改的地方是什么地方?
//根据传入的 socket对象,创建一个PrintWriter的对象,这个对象用来向服务器发送字符串.明白吧明白.师父.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String IP = GetMyUserIP.getMyIP();
content = content.replaceAll("\n", "<br>");
String str = content + "龘"+ SocketClient1st.myprojectversion + "龘" + DRecv.MyportSysNum+ "龘" +"D"+ "龘"+ IP + "龘" + MyThreadname + "\r\n";
this.str = str;
}
public void run(){//这部分的代码用于向服务器发送字符串
try {
out.println(this.str+"\r");
System.out.println("++++++++++++++++++++++++++"+str);
out.flush();
System.out.println("++++Client端write下方++++"+this.str);
// s.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
(客户端与服务器的向txt文件写出内存中的数据的类型)
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
/**
* 程序入口类:系统上帝之手端点.
*
* @author 楚留香 <如转载请保留作者和出处>
* @q-zone http://user.qzone.qq.com/745083865/infocenter?ptsig=EDxu09--a8Psawk9ZTT5c-VHXcfcRnqVjwC3dCNjLXo_
*/
public class GetCportSocket extends Thread {
public static String myUserNum;
}
(参与服务器端与客户端计算的辅助类)
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.swing.JButton;
public class MyJButtonLogin extends JButton {
String S_PORT_SERVER = "localhost";
String D_PORT_SERVER = "localhost";
static String MyUID0;
static String MyPWD0 = "";
InputStream inputstream = null;
boolean isMyUser = false;
String MySysNum = null;
public static String MyUID = null;
public static String MyPWD = null;
String str2 = null;
public static String str3 = null;
String str4 = null;
// Login log = null;
static SocketClient so3 = null;
String[] buffer = null;
String str = "";
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param args
*/
public MyJButtonLogin(String button, String UID, String pwd) {
super(button);
InetAddress addr = null;
try {
addr = InetAddress.getLocalHost();
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
str3 = addr.getHostAddress().toString();// 获得本机IP
this.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent et) {
MyUID = MyUID0 = "褚彦明";
MyPWD = MyPWD0 = "cjcjcjcjcocococo!!";
String aa = "0丗" + MyUID0 + "丠" + MyPWD0 + "丠" + "Mem" + "丠"
+ str3 + "丗" + "C" + "丗" + "Mem" + "丗" + "2";
try {
} catch (NullPointerException e) {
}
}
});
}
}
(服务器端的辅助类)
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.concurrent.ArrayBlockingQueue;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class NRecv0 {
static String MyportSysNum = "a1";
public static int myprojectversion = 1;
/**
* @param args
*/
public static void main(String[] args) {
new NRecv0();
}
public NRecv0() {
}}
(服务器端的辅助类)
public class Recv {
public static Integer MySystemserialnum = 29;
static String Y_PORT_SERVER = "127.0.0.1";
static String D_PORT_SERVER = "127.0.0.1";
}
(服务器与客户端辅助类)
/////////////////////////////////////////////////////////
//Bare Bones Browser Launch //
//Version 1.5 (December 10, 2005) //
//By Dem Pilafian //
//支持: Mac OS X, GNU/Linux, Unix, Windows XP//
//可免费使用 //
/////////////////////////////////////////////////////////
/**
* @author Dem Pilafian
* @author John Kristian
*/
import java.lang.reflect.Method;
public class BareBonesBrowserLaunch {
public static void openURL(String url) {
try {
browse(url);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args){
// BareBonesBrowserLaunch.openURL("www.baidu.com");
try {
BareBonesBrowserLaunch.browse("www.baidu.com");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void browse(String url) throws Exception {
// 获取操作系统的名字
String osName = System.getProperty("os.name", "");
if (osName.startsWith("Mac OS")) {
// 苹果的打开方式
Class fileMgr = Class.forName("com.appl
走同样的路,发现不同的人生