我是一名学习软件工程的学生,在2月份刚刚转学的Java语言,Swing和Socket编程,现在,正在写弟我的“第一个Java作品”:
一个CS结构的聊天系统,工程代码行数到现在,已经写了近8K行代码了....
我将我的作品,面向市场,进行了三个端点的设计:
1.D端:开发者端.
2.S端:运营商端.
3.C端:客户端.
现在,弟我需要将作品,进行集成测试.弟我已经将“能够提出的干架类和必须进行提取的基本功能类”进行了提拣了.
由于是第一次进行的这个工作,我的经验还不充分,现在碰到了下面的错误,希望得到高手的解答.
代码结构设计如下:
首先需要运行D端的代码,在D端的程序跑起来后,S端的程序,连接D端,C端的用户,连接D端和S端..
代码的运行错误场景如下:
在弟我首先运行了D端的入口类代码后,console窗口无错.然后,弟我运行了S端的入口类代码后,S端的console窗口报出的错误如下:
弟我的D端的入口类代码如下:
package d_port_package;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class D_Updata_c_port_Data {
static int[] Localmemberonline = new int[200];
DataInputStream dips0 = null;
ServerSocket ss1 = null;
Socket s1 = null;
Socket s2 = null;
byte b = 'b';
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new D_Updata_c_port_Data().startGetValue();
}
public void startGetValue(){
try {
ss1 = new ServerSocket(9999,50);
while(true){
s1 = ss1.accept();
dips0 = new DataInputStream(s1.getInputStream());
int condition = dips0.read();
switch(condition){
case 'a':
{
D_ManageTheChannel11DS m11 = new D_ManageTheChannel11DS(s1,"Thread_11");
m11.start();
D_ManageTheChannel12DS m12 = new D_ManageTheChannel12DS(s2,"Thread_12");
m12.start();
}
case 'b':
{
D_ManageTheChannel21DS m21 = new D_ManageTheChannel21DS(s1,"Thread_21");
m21.start();
D_ManageTheChannel22DS m22 = new D_ManageTheChannel22DS(s2,"Thread_22");
m22.start();
}
case 'F':
{
D_portManageTheSysRegister m3 = new D_portManageTheSysRegister(s1,"Thread_3");
m3.start();
}
case 'M':
{
D_ManageTheChannel31DS m4 = new D_ManageTheChannel31DS(s1,"Thread_4");
m4.start();
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
弟我的S端的入口类代码如下:
package s_port_package_BeiJing;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Arrays;
import java.util.HashMap;
import javax.swing.JFrame;
public class ChatServer extends JFrame {
/**
* ChatServer.java
* 2013-5-9
* @author cjco
*/
//全局定义区域:定义各种成员变量;
ServerSocket ss1 = null;
public static int Index = 0;
static int num = 0;
int[] a = null;
int condition = -1;
private static final long serialVersionUID = 1L;
boolean started = false;
static Socket so1;
Socket so4;
static int PM_linknumlog = 0;
DataOutputStream dos1 = null;
DataOutputStream dos2 = null;
DataOutputStream dos3 = null;
DataInputStream dis1 = null;
DataInputStream dis2 = null;
DataInputStream dis3 = null;
ObjectOutputStream oops = null;
static int[] Localstaff = new int[200];
static int[] Localmemberonline = new int[200];
static int[] membercomplicatingnum = new int[200];
//系统为注册所创建的对象,为了代码维护的方便.
public static S_port_ChatClientmember_DS JB0 = null;
public static S_port_ChatClientmember_DS JB1 = null;
public static S_port_ChatClientmember_DS JB2 = null;
public static S_port_ChatClientmember_DS JB3 = null;
public static S_port_ChatClientmember_DS JB4 = null;
public static S_port_ChatClientmember_DS JB5 = null;
public static S_port_ChatClientmember_DS JB6 = null;
public static S_port_ChatClientmember_DS JB7 = null;
public static S_port_ChatClientmember_DS JB8 = null;
public static S_port_ChatClientmember_DS JB9 = null;
public static S_port_ChatClientmember_DS JB10 = null;
public static S_port_ChatClientmember_DS JB11 = null;
public static S_port_ChatClientmember_DS JB12 = null;
public static S_port_ChatClientmember_DS JB13 = null;
public static S_port_ChatClientmember_DS JB14 = null;
public static S_port_ChatClientmember_DS JB15 = null;
public static S_port_ChatClientmember_DS JB16 = null;
public static S_port_ChatClientmember_DS JB17 = null;
public static S_port_ChatClientmember_DS JB18 = null;
public static S_port_ChatClientmember_DS JB19 = null;
public static S_port_ChatClientmember_DS JB20 = null;
public static S_port_ChatClientmember_DS JB21 = null;
public static S_port_ChatClientmember_DS JB22 = null;
public static S_port_ChatClientmember_DS JB23 = null;
public static S_port_ChatClientmember_DS JB24 = null;
public static S_port_ChatClientmember_DS JB25 = null;
public static S_port_ChatClientmember_DS JB26 = null;
public static S_port_ChatClientmember_DS JB27 = null;
public static S_port_ChatClientmember_DS JB28 = null;
public static HashMap<Byte,S_port_ChatClientcustomer_DS> mapcustomer = new HashMap<Byte,S_port_ChatClientcustomer_DS>();
public static HashMap<Byte,S_port_ChatClientmember_DS> mapmember = new HashMap<Byte,S_port_ChatClientmember_DS>();
public static void main(String[] args) {
new ChatServer().start();
}
public static int creatIndex(){
int memberSystemIndex = ChatServer.Index++;
return memberSystemIndex;
}
//“C端用户的其他Socket请求的"交给线程处理"动作。
public void start(){
try {
final String D_PORT_SERVER = "127.0.0.1";
final String S_PORT_SERVER = "127.0.0.1";
final String C_PORT_CLIENT = "127.0.0.1";
Arrays.fill(Localmemberonline, 0);
// TODO Auto-generated method stub
File f=new File("D://MyDoc//Chatlog.txt");
Socket s4 = new Socket(D_PORT_SERVER,9999);
ss1 = new ServerSocket(8888,50);
DataOutputStream dops0 = new DataOutputStream(so1.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(true){
//创建绑定到端口8888的ServerSocket对象
try {
so1 = ss1.accept();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(so1+"|||---");
System.out.println("服务器正在对8888端口进行监听");
//服务器循环接受客户端的请求,为不同的客户端提供服务
InputStream in;
try {
in = so1.getInputStream();
BufferedReader buffReder = new BufferedReader(new InputStreamReader(in));
condition = buffReder.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
switch(condition){
case 0:
{
ManageTheChannel0ConfirmandSaveDS m0 = new ManageTheChannel0ConfirmandSaveDS(so1,"Thread0");
m0.start();
break;
}
case 1:
{
ManageTheChannel1SendInfo m1 = new ManageTheChannel1SendInfo(so1,"Thread1");
m1.start();
break;
}
case 2:
{
ManageTheChannel2ExitSysGivOrderNum m2 = new ManageTheChannel2ExitSysGivOrderNum(so1,"Thread2");
m2.start();
break;
}
case 3:
{
}
}
}
}
}
希望高手能够根据我的错误场景,为我做出错误原因的分析与点拨.
谢谢高手!!
一百分奉上!!
一位日日夜夜向着理想奔跑的筑梦者
2013年8月16日下午19点58分星期五
3 个解决方案
#1
顶起!!
求CSDN专家,版主,为我解答我的问题!!
绝不辜负培养帮助我的高手的心血!!
求CSDN专家,版主,为我解答我的问题!!
绝不辜负培养帮助我的高手的心血!!
#2
java.net.SocketException: (Connection reset或者Connect reset by peer:Socket write error)。该异常在客户端和服务器端均有可能发生,引起该异常的原因有两个,第一个就是如果一端的Socket被关闭(或主动关闭或者因为异常退出而引起的关闭),另一端仍发送数据,发送的第一个数据包引发该异常(Connect reset by peer)。另一个是一端退出,但退出时并未关闭该连接,另一端如果在从连接中读数据则抛出该异常(Connection reset)。简单的说就是在连接断开后的读和写操作引起的。
俺也是看来滴,你看看有用木
http://blog.csdn.net/allanking666/article/details/5020864
俺也是看来滴,你看看有用木
http://blog.csdn.net/allanking666/article/details/5020864
#3
谢谢e274794140兄弟的点拨!!
谢谢您!!
一百分奉上!!
谢谢您!!
一百分奉上!!
#1
顶起!!
求CSDN专家,版主,为我解答我的问题!!
绝不辜负培养帮助我的高手的心血!!
求CSDN专家,版主,为我解答我的问题!!
绝不辜负培养帮助我的高手的心血!!
#2
java.net.SocketException: (Connection reset或者Connect reset by peer:Socket write error)。该异常在客户端和服务器端均有可能发生,引起该异常的原因有两个,第一个就是如果一端的Socket被关闭(或主动关闭或者因为异常退出而引起的关闭),另一端仍发送数据,发送的第一个数据包引发该异常(Connect reset by peer)。另一个是一端退出,但退出时并未关闭该连接,另一端如果在从连接中读数据则抛出该异常(Connection reset)。简单的说就是在连接断开后的读和写操作引起的。
俺也是看来滴,你看看有用木
http://blog.csdn.net/allanking666/article/details/5020864
俺也是看来滴,你看看有用木
http://blog.csdn.net/allanking666/article/details/5020864
#3
谢谢e274794140兄弟的点拨!!
谢谢您!!
一百分奉上!!
谢谢您!!
一百分奉上!!