求高手点拨一个“Java Socket通信”的问题..
高手,您好:我做了一个im聊天系统,其中,我的设计是:
三个“系统端点角色”:
1.D端:开发者端.
2.S端:运营商端.
3.C端:客户端.
首先D端运行,S端运行后,连接D端.然后C端运行,C端连接S端,再连接D端.
现在我已经将前面两个连接做成了.
但是,我的C端,连接D端,这个动作,却“反复检查后”“无法连接成功”...
我的“参与C端连接D端”这个动作的类型源代码如下:
C端“RelayNo1类”:
D端对应的“接收C端本图中所报数据的类型D_Updata_c_port_Data类”部分源代码如下:
while(true){
Socket so1 = sso1.accept();
al19.add(so1);
dips0 = new DataInputStream(so1.getInputStream());
String buffer = dips0.readUTF();
System.out.println("D:"+buffer);
String[] buffertemp = buffer.split("[#]");
condition = Integer.parseInt(buffertemp[0]);
System.out.println(condition);
para = Integer.parseInt(buffertemp[1]); //S端:标记符.暂无意义.
System.out.println(para);
MyUserRole = buffertemp[2]; //S端:运营学校的具体名称.
System.out.println(MyUserRole);
MyUserOnlineWorkNum = buffertemp[3];//待修改. //S端:要求服务标记符.“0”为要求“传输用户注册数据”.“1”为要求“向D端传输教师用户的并发接单数”“要求D端接收”.
System.out.println(MyUserOnlineWorkNum);
SocketData = buffertemp[4]; //S端:运营商传送来的数据.
System.out.println(SocketData);
MySysRole = buffertemp[5];//D或者C或者S. //S端:S.
MyServerPhysicalPlace = buffertemp[6];//BeiJing或者YinChuan. //S端:运营商所在城市.
System.out.println(MyServerPhysicalPlace);
if(CrackerProfitNum==1){
if(crackeronline==true){
CrackerProfitNum = 0;
Complete_ManageTheCopyRightValue m10 = null;
m10 = new Complete_ManageTheCopyRightValue(Sysal8,Sysal0,CrackerProfitFileNum);
m10.start();
}else{
Sysal8.clear();
Sysal0.clear();
CrackerProfitFileNum = 0;
crackeronline= false;
}
}
if(MyUserRole.equals("Customer")){
mapCustomerOnline.put(Integer.valueOf(MyUserOnlineWorkNum),new D_port_SysUserClient_DS(so1,true));
}else{
mapTeacherOnline.put(Integer.valueOf(MyUserOnlineWorkNum),new D_port_SysUserClient_DS(so1,true));
}
int SportNeedService = Integer.parseInt(MyUserOnlineWorkNum);
int SportcityID = GetCityIndex.getCityIndex(MyServerPhysicalPlace);
int SportHospitalID = GetHospitalIndex.getHospitalIndex(MyUserRole);
if(MySysRole.equals("S")){
DataOutputStream dops3 = new DataOutputStream(so1.getOutputStream());
switch(SportNeedService){
case 0:
{
switch(SportcityID){
case 0:
{
switch(SportHospitalID){
case 0:
{
//面向北京四中,进行“注册用户账户”数据的推送。
Complete_D_portManageTheUserDataSendtoBeiJing0Sport m7 = new Complete_D_portManageTheUserDataSendtoBeiJing0Sport(dops3,"Thread_7");
m7.start();
break;
}
case 1:
{
//面向清华大学附属中学,进行“注册用户账户”数据的推送.
}
case 2:
{
//
}
}
}
case 1:
{
switch(SportHospitalID){
case 0:
{
//面向银川新二中,进行“注册用户账户”数据的推送。
Complete_D_portManageTheUserDataSendtoYinChuan0Sport m8 = new Complete_D_portManageTheUserDataSendtoYinChuan0Sport(dops3,"Thread_8");
m8.start();
break;
}
case 1:
{
//面向银川新一中,进行“注册用户账户”数据的推送.
}
case 2:
{
//
}
}
}
case 2:
{
switch(SportHospitalID){
case 0:
{
//面向包头市第一中学 ,进行“注册用户账户”的数据的推送.
}
case 1:
{
//面向包头市第三十三中学 ,进行“注册用户账户”的数据推送.
}
}
}
}
}
case 1:
{
switch(SportcityID){
case 0:
{
switch(SportHospitalID){
case 0:
{
//面向北京四中进行的数据接收功能线程。
Complete_D_ManageTheChannel11DSRecvSportClientNum m1 = new Complete_D_ManageTheChannel11DSRecvSportClientNum("Thread_1",SocketData);
m1.start();
break;
}
case 1:
{
//面向清华大学附属中学,进行“注册用户账户”数据的推送.
}
case 2:
{
//
}
}
}
case 1:
{
switch(SportHospitalID){
case 0:
{
//面向银川新二中进行的数据接收功能线程。
Complete_D_ManageTheChannel21DSRecvSportClientNum$ m3 = new Complete_D_ManageTheChannel21DSRecvSportClientNum$("Thread_3",SocketData);
m3.start();
break;
}
case 1:
{
//面向银川新一中,进行“注册用户账户”数据的推送.
}
case 2:
{
//
}
}
}
case 2:
{
switch(SportHospitalID){
case 0:
{
//面向包头市第一中学 ,进行“注册用户账户”的数据的推送.
}
case 1:
{
//面向包头市第三十三中学 ,进行“注册用户账户”的数据推送.
}
}
}
}
}
}
}else{
DataOutputStream dops1 = new DataOutputStream(so1.getOutputStream());
switch(condition){
case 1://面向C端北京昌平区和银川金凤区用户的“产品授权码”,所开设的“验证线程”.
{
Complete_ManageOurCustomerProductRightsConfirm m1 = new Complete_ManageOurCustomerProductRightsConfirm(SocketData,dops1);
m1.start();
break;
}
case 2://面向C端北京昌平区郑各庄村进行的用户广告推送的功能线程。
{
Complete_D_ManageTheChannel12DSSendUserAccounttoSportBeiJing0User m2 = new Complete_D_ManageTheChannel12DSSendUserAccounttoSportBeiJing0User(dops1,"Thread_2",SocketData);
m2.start();
break;
}
case 3:
{
}
case 4://面向C端银川金凤区用户进行广告推送的功能线程。
{
Complete_D_ManageTheChannel22DSSendUserAccounttoSportYinChuan0User m4 = new Complete_D_ManageTheChannel22DSSendUserAccounttoSportYinChuan0User(dops1,"Thread_4",SocketData);
m4.start();
break;
}
case 5://面向系统用户进行“注册功能”的实现。//已核对.
{
D_portManageTheSysRegister m5 = new D_portManageTheSysRegister(so1,"Thread_5",SocketData,para);
m5.start();
break;
}
case 9:
{
Complete_ManageTherewardOfourOwntoil m9 = new Complete_ManageTherewardOfourOwntoil(SocketData,dops1,para);
m9.start();
break;
}
本代码块中,最后一个“case 9分支”,子线程“Complete_ManageTherewardOfourOwntoil类型”,他是负责“验证用户是否在授权期限内,并且给出返回值”:C端是否有权利“下一步”的功能实现类..
他的源代码,由于篇幅原因,请高手见下帖...
socket 通信 im聊天 java调试 --------------------编程问答-------------------- 负责D端的“验证C端用户的授权”的类型,子线程Complete_ManageTherewardOfourOwntoil,他的源代码如下:
package d_port_package;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
public class Complete_ManageTherewardOfourOwntoil extends Thread{
String MyData = null;
String OurUserNum = null;
Integer OurUserNumInteger = -1;
String MyUserPlace = null;
String MyUserRole = null;
String MyPWD = null;
String[] buffer = null;
boolean buffertemp = false;
int ServiceNum = -1;
long MyauthorizeTime = -1;
long Nowtime = -1;
boolean isInAuthorizeTime = false;
Socket so1 = null;
DataOutputStream Localdops1 = null;
public Complete_ManageTherewardOfourOwntoil(String Data,DataOutputStream dops1,int para){
System.out.println("D_port_9_thread_start_23");
MyData = Data;
System.out.println(MyData);
buffer = MyData.split("[%]");
OurUserNum = buffer[0];
OurUserNumInteger = Integer.parseInt(OurUserNum);
MyPWD = buffer[1];
MyUserPlace = buffer[2];
MyUserRole = buffer[3];
Nowtime = GetLocalTime.GetNowLocalTime();
Localdops1 = dops1;
}
public void run(){
System.out.println("D_port_9_thread_run_method_start");
if(MyUserPlace.equals("BeiJing")){
System.out.println("OurBeiJingUser");
if(MyUserRole.equals("Teacher")){
D_Updata_c_port_Data.LocalBeiJingmemberonline[OurUserNumInteger]=1;
if(!MyPWD.equals(D_Updata_c_port_Data.BJMemPWD.get(OurUserNumInteger))){
if(D_Updata_c_port_Data.BJMemUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_1st_SecondUploadOurSys_TeacherLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
try {
Localdops1.writeUTF("LoverRelayPlanStart");
Localdops1.writeUTF("Please_Check_Your_PWD");
System.out.println("9Thread_1st_TeacherpwdnotrightAndLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
if(D_Updata_c_port_Data.BJMemUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_2nd_TeacherloverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
ReadTxt.read(D_Updata_c_port_Data.BeiJingMyMemRegTimePath);
MyauthorizeTime=Long.parseLong(ReadTxt.logData.get(OurUserNumInteger));
isInAuthorizeTime = new D_port_Calc_Client_UseRight(MyauthorizeTime,Nowtime).Calc();
try {
String sendInfo = isInAuthorizeTime==true?"true":"false";
Localdops1.writeUTF(sendInfo);
if(sendInfo.equals("true")){
System.out.println("OurTeacherisInauthorizeTime");
}else{
System.out.println("OurTeacherisOutOfauthorizeTime");
}
if(isInAuthorizeTime==false){
D_Updata_c_port_Data.BJMemUserisInbufferTime.set(OurUserNumInteger,1);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
}else{
if(!MyPWD.equals(D_Updata_c_port_Data.BJCusPWD.get(OurUserNumInteger))){
if(D_Updata_c_port_Data.BJCusUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_3rd_CustomerLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
try {
Localdops1.writeUTF("LoverRelayPlanStart");
Localdops1.writeUTF("Please_Check_Your_PWD");
System.out.println("9Thread_4th_CustomerpwdnotrightAndLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
if(D_Updata_c_port_Data.BJCusUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_5th_LoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
ReadTxt.read(D_Updata_c_port_Data.BeiJingMyCusRegTimePath);
MyauthorizeTime=Long.parseLong(ReadTxt.logData.get(OurUserNumInteger));
isInAuthorizeTime = new D_port_Calc_Client_UseRight(MyauthorizeTime,Nowtime).Calc();
try {
String sendInfo = isInAuthorizeTime==true?"true":"false";
Localdops1.writeUTF(sendInfo);
if(sendInfo.equals("true")){
System.out.println("OurCustomerisInauthorizeTime");
}else{
System.out.println("OurCustomerisOutOfauthorizeTime");
}
if(isInAuthorizeTime==false){
D_Updata_c_port_Data.BJCusUserisInbufferTime.set(OurUserNumInteger,1);
System.out.println("AddMyUsertobufferTimelist");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
}
}else{
System.out.println("OurYinChuanUser");
if(MyUserRole.equals("Teacher")){
D_Updata_c_port_Data.LocalYinChuanmemberonline[OurUserNumInteger]=1;
if(!MyPWD.equals(D_Updata_c_port_Data.YCMemPWD.get(OurUserNumInteger))){
if(D_Updata_c_port_Data.YCMemUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_1st_SecondUploadOurSys_TeacherLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
try {
Localdops1.writeUTF("LoverRelayPlanStart");
Localdops1.writeUTF("Please_Check_Your_PWD");
System.out.println("9Thread_1st_TeacherpwdnotrightAndLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
if(D_Updata_c_port_Data.YCMemUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_2nd_TeacherloverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
ReadTxt.read(D_Updata_c_port_Data.YinChuanMyMemRegTimePath);
MyauthorizeTime=Long.parseLong(ReadTxt.logData.get(OurUserNumInteger));
isInAuthorizeTime = new D_port_Calc_Client_UseRight(MyauthorizeTime,Nowtime).Calc();
try {
String sendInfo = isInAuthorizeTime==true?"true":"false";
Localdops1.writeUTF(sendInfo);
if(sendInfo.equals("true")){
System.out.println("OurTeacherisInauthorizeTime");
}else{
System.out.println("OurTeacherisOutOfauthorizeTime");
}
if(isInAuthorizeTime==false){
D_Updata_c_port_Data.YCMemUserisInbufferTime.set(OurUserNumInteger,1);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
}else{
if(!MyPWD.equals(D_Updata_c_port_Data.YCCusPWD.get(OurUserNumInteger))){
if(D_Updata_c_port_Data.YCCusUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_3rd_CustomerLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
try {
Localdops1.writeUTF("LoverRelayPlanStart");
Localdops1.writeUTF("Please_Check_Your_PWD");
System.out.println("9Thread_4th_CustomerpwdnotrightAndLoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}else{
if(D_Updata_c_port_Data.YCCusUserisInbufferTime.get(OurUserNumInteger)==1){
try {
Localdops1.writeUTF("LoverRelayPlanStart");
System.out.println("9Thread_5th_LoverRelayPlanStart");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}else{
ReadTxt.read(D_Updata_c_port_Data.YinChuanMyCustomerRegTimePath);
MyauthorizeTime=Long.parseLong(ReadTxt.logData.get(OurUserNumInteger));
isInAuthorizeTime = new D_port_Calc_Client_UseRight(MyauthorizeTime,Nowtime).Calc();
try {
String sendInfo = isInAuthorizeTime==true?"true":"false";
Localdops1.writeUTF(sendInfo);
if(sendInfo.equals("true")){
System.out.println("OurCustomerisInauthorizeTime");
}else{
System.out.println("OurCustomerisOutOfauthorizeTime");
}
if(isInAuthorizeTime==false){
D_Updata_c_port_Data.YCCusUserisInbufferTime.set(OurUserNumInteger,1);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
}
}
}
}
根据D端的console窗口,他给出的打印输出显示出的信息是:
D端,没有接收到C端的连接.
我已经仔细检查我的代码好几遍,都没有发现错误...
请问高手,我的错误,可能出现在什么地方...?
谢谢高手!!
一百分奉上!!
一位日日夜夜向着理想奔跑的筑梦者
2013年10月20日星期日下午15点35分
补充:Java , Java SE