0 0

关于socket的connection reset!5

我写的是SOCKET的客户端代码。。需要向服务端发送一个注册的请求。。

首先,我得发送一个字符串过去申请登录,登录成功对方会返回一个会话ID。然后我再发请求时要把这个ID带上,但我第2次用流向对方write的时候。就报连接重置的异常。

我的代码如下:

 

 

socket = new Socket(InetAddress.getByName(address),port);
			LOG.error("seccuse1");
			if (socket != null) {
				LOG.error("DATAING");
				InputStream in = socket.getInputStream();
				OutputStream out = socket.getOutputStream();
				String reqstinfo1 = reqstinfo1head + reqstinfo1body + reqstinfo1end;
				byte[] request = reqstinfo1.getBytes();
				LOG.error("request1" + request);
				LOG.error("request1" + request);
				LOG.error("request1" + request);
				out.write(request);
				int length = in.read(returnHeadBytesArray);
				head = new String (returnHeadBytesArray);
				resultMap.put("reqstinfo1", head);
				LOG.error("head1" + head);
				LOG.error("head1" + head);
				LOG.error("head1" + head);
				String check_r2 = reqstinfo2head + reqstinfo2body + reqstinfo2end;
				LOG.error("check_r2" + check_r2);
				LOG.error("check_r2" + check_r2);
				LOG.error("check_r2" + check_r2);
				String infohe = "";
				if (check_r2 != null && !"".equals(check_r2)) {
					if (changebody != null && !"".equals(changebody)) {
						reqstinfo2body = reqstinfo2body.substring(0, reqstinfo2body.length() - lengthc)
							+ head.substring(beginc, beginc + lengthc);
						infohe = calcCheckSum(reqstinfo2body + reqstinfo2end);
					}
					String reqstinfo2 = reqstinfo2head + reqstinfo2body + reqstinfo2end + infohe;
					LOG.error("reqstinfo2" + reqstinfo2);
					LOG.error("reqstinfo2" + reqstinfo2);
					LOG.error("reqstinfo2" + reqstinfo2);
					LOG.error("reqstinfo2" + reqstinfo2);
					LOG.error("reqstinfo2" + reqstinfo2);
					if (reqstinfo2 != null && !"".equals(reqstinfo2)) {
						request = reqstinfo2.getBytes();
						LOG.error("--------------------------------" + request.length);
						LOG.error("request2" + request);
						LOG.error("request2" + request);
						LOG.error("request2" + request);
						out.write(request);

//						Map param = new HashMap();
//						param.put("request", reqstinfo2);
//						param.put("socket", socket);
//						param.put("arrsize", arrsize+"");
//						Map reMap = (Map)ESBClientService.call("zj/ismp/ecp/create/account2", "create/account", "翼聊开户", param);

						LOG.error("------------------------------");
						returnHeadBytesArray = new byte[arrsize];
						length = in.read(returnHeadBytesArray);
						head = new String (returnHeadBytesArray);
//						head = (String)reMap.get("head");
						resultMap.put("reqstinfo2", head);

 

第42行执行的时候报的异常。

 

 

ERROR[PRIORITY] ncom.ct10000.esb.service.impl.MySocketService[CATEGORY]

--------------IOException----------------[MESSAGE]

2012-03-21 17:37:02,111 ERROR [STDERR] java.net.SocketException: Connection reset

2012-03-21 17:37:02,112 ERROR [STDERR]  at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)

2012-03-21 17:37:02,112 ERROR [STDERR]  at java.net.SocketOutputStream.write(SocketOutputStream.java:124)



我问过服务端的人。。他们说没有接收到我第2次传送的字符数组。

请问这是为什么呢??菜鸟啊,没什么积分。求大神帮帮忙,弄了好几天了。。
2012年3月21日 17:58

2个答案 按时间排序 按投票排序

0 0

服务器端在客户端运行第一次结束的时候也跟着结束了,所以在客户端第二次写数据的时候服务器并没有开启,所以才会有服务器端链接重置的异常。也就是说你客户端第二次之后根本就写不出去。

2012年3月23日 22:49
0 0

很有可能服务器第一次返回ID后就主动断开了连接.

所以你继续用这个连接发送第2次请求才会出错.

2012年3月21日 18:30

相关推荐

    java.net.SocketException Connection reset 解决方法

    "java.net.SocketException Connection reset 解决方法" 在 Java 编程中,SocketException 是一种常见的异常,特别是在网络编程中。Conexion reset by peer 是一种特殊的 SocketException,它发生在客户端和服务器...

    socket 超大文件上传

    delphi客户端 ICS 代码。 上传 到 socket, 超大文件上传 4G,解决了 out of memory 和connection reset 问题

    关于eclispe的“cannot connect to VM”

    很多同学都说在用Eclispe出现“cannot connect to VM” 。现在给你们解决!

    Modbus TCP客户端和服务器示例

    基于我们开源的Modbus协议栈实现的Modbus TCP客户端和服务器示例,使用VS2019开发。

    python socket 超时设置 errno 10054

    python socket.error: [Errno ...这个错误是connection reset by peer.也就是传说的远端主机重置了此连接。原因可能是socket超时时间过长;也可能是request = urllib.request.urlopen(url)之后,没有进行request.cl

    linux系统上的java程序连接oracle错误超时

    在linux上通过JDBC连接ORACLE 时总是出现 java.sql.SQLRecoverableException: IO Error: Connection reset 的问题

    Project-Never-Say-Never:使用Phaser.js和Socket.io的2D MMORPG

    使用Phaser.js和Socket.io的2D MMORPG 在在线代码编辑器运行 安装指南 注意:如果您只想运行项目,则可以直接 如果要下载要在计算机上运行的项目,则必须做一些事情才能使其全部工作: 1.您将需要创建一个具有几个...

    Loadrunner报错日志

    二、问题描述Connection reset by peer. 这个问题不多遇见,一般是由于下载的速度慢,导致超时,所以,需要调整一下超时时间。 解决办法:Run-time setting窗口中的‘Internet Protocol’-‘Preferences’设置set ...

    php.ini-development

    ;;;;;;;;... 1.... 2.... 3.... 4.... 5.... 6.... The syntax of the file is extremely simple.... Section headers (e.g.... at runtime.... There is no name validation.... (e.g.... previously set variable or directive (e.g....

    qemu-0.13.0(编译过全处理器支持)

    connect the vlan 'n' to another VLAN using a socket connection -net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port] connect the vlan 'n' to multicast maddr and port -net dump[,vlan=n][,file=f]...

    The Indispensable PC Hardware Book - rar - part1. (1/7)

    AMD K6 II and AMD K6 III with Super Socket 7. IDT WinChip C6. CPU Overview and settings. 12. Pure 32-bit technology—The Pentium Pro. Pins and signals. Internal structure. Functional units of ...

    Qemu-1.0.1 for windows

    connect the vlan 'n' to another VLAN using a socket connection -net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port[,localaddr=addr]] connect the vlan 'n' to multicast maddr and port use '...

    softap_ap6212a0_tinav2.1_验证通过_旧版本的系统_20170915_1223没有外层目录.7z

    < > SCTP protocol connection tracking support (EXPERIMENTAL) < > UDP-Lite protocol connection tracking support < > Amanda backup protocol support < > FTP protocol support < > H.323 protocol ...

    Bochs - The cross platform IA-32 (x86) emulator

    Changes in 2.4.6 (February 22, 2011): Brief summary : - Support more host OS to run on: - Include win64 native binary in the release. - Fixed failures on big endian hosts. - BIOS: Support for up to...

    ZendFramework中文文档

    2.1.1. 关于资源(Resource) 2.1.2. 关于角色(Role) 2.1.3. 创建访问控制列表(ACL) 2.1.4. 注册角色(Role) 2.1.5. 定义访问控制 2.1.6. 查询 ACL 2.2. 精细的访问控制 2.2.1. 精细的访问控制 2.2.2. 除去访问...

    Sakemail

    just go tohttp://groups.yahoo.com/group/sakemail/History:0.9 - First released version0.9.1b -Fixed when a mail server reply on the connection with more than one line0.9.2b - I forget to return a ...

    BURNINTEST--硬件检测工具

    - A network connection and the TCP/IP networking software installed for the Network Tests Pro version only: - A serial port loop back plug for the serial port test. - A parallel port loop back plug...

Global site tag (gtag.js) - Google Analytics