62,614
社区成员
发帖
与我相关
我的任务
分享
if(mytaskstate == 1){
System.out.println("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
D_port_Calc_The_CustomerSysFuctionUserRightsCode cjco = new D_port_Calc_The_CustomerSysFuctionUserRightsCode();
String MyCustomerServiceOrdernum = cjco.getMyUserRights(MyUserRights);
SocketClient so = new SocketClient(MyObjIP,5555);
String mycustomerordernum = "6丗6丗"+MyCustomerServiceOrdernum+"丠"+"Cus"+"丠"+"99999999"+"丠"+"IneedOrders丮false" +"丗"+"D";
so.writeStr(mycustomerordernum, "ManageOurAuthorizeRightsConfirmCode");
so.getMyResourceBack();
System.out.println("OKay!!The Data I Out put is:"+mycustomerordernum);
}
while(true){
Socket s1 = soo1.nextSocket();
IP = s1.getInetAddress();
MyObjIP = IP.toString().substring(1);
synchronized(s1){
try {
buffertemp3 = soo1.read(s1);
} catch (IOException e) {
// TODO Auto-generated catch block
new NoteUserSysIsInDefending();
}
}
//////"D-C传输一笔数据");
// //////////"C端接收到S端的数据!!D-C端系统信道启动!!");
// ////buffertemp3);
//////"C端接收到的数据:buffertemp3----->"+buffertemp3);
System.out.println("GetDportSocket类接收到的服务器的传输数据" + buffertemp3);
String[] bufferData3 = buffertemp3.split("丗");
System.out.println("GetDportSocket类接收服务器传输数据的字符串数组"+bufferData3);
sign3 = Integer.parseInt(bufferData3[0]);
System.out.println("GetDportSocket类接收到的数据第一字段:sign3----->"+sign3);
para3 = Integer.parseInt(bufferData3[1]);
System.out.println("GetDportSocket类接收到的数据第二字段:para3----->"+para3);
SocketInfo = bufferData3[2];
System.out.println("GetDportSocket类接收到的第三字段:SocketInfo----->"+SocketInfo);
MyUserRole = bufferData3[3];
System.out.println("GetDportSocket类接收到的第四字段:MyUserRole----->"+MyUserRole);
MyObjIP = bufferData3[4];
System.out.println("GetDportSocket类接收到的第五字段:MyObjIP----->"+MyObjIP);
MyThreadname = bufferData3[5];
System.out.println("GetDportSocket类接收到的D端的线程:MyThread----->"+MyThreadname);
package c_port_packageBJTeacher;
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 (IOException e) {
e.printStackTrace();
}
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);
}
return br.readLine();
}
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) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(rm!=null){
rm.clear();
}if(wm!=null){
wm.clear();
}if(ss!=null){
try {
ss.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
package c_port_packageBJTeacher;
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.Socket;
public class SocketClient {
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 SocketClient(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) {
e.printStackTrace();
}
}
public String readStr() throws IOException {
synchronized (this.in) {
return this.inStr.readLine();
}
}
public void writeStr(String content,String MyThreadname) {
synchronized (this.out) {
String IP = GetMyUserIP.getMyIP();
outStr.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) {
e.printStackTrace();
}
// long progress = 0;
// while (size != (progress = getServerReceiveSize())) {
// //////System.out.println("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) {
e.printStackTrace();
}
}
}
private long getServerReceiveSize() {
synchronized (in) {
byte[] b = new byte[19];
try {
this.in.read(b);
} catch (IOException e) {
e.printStackTrace();
}
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(inStr!=null){
try {
inStr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}if(outStr!=null){
outStr.close();
}
if(s!=null){
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}if(in!=null){
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}if(out!=null){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}