客户端与服务器之间通信收不到信息——readLine()
写服务器端和客户端之间通信,结果一直读取不到信息,在https://blog.csdn.net/yiluxiangqian7715/article/details/50173573
上找到了原因:使用BufferedReader的readLine()方法来读取信息,但是没有遇见行结束符“\n”,“\r”或“\r\n”还是会继续读取(即阻塞了),所以要想读取到信息,只需要在写入的时候加上行结束符。
BufferedReader的readLine方法源码如下:
/*** Reads a line of text. A line is considered to be terminated by any one* of a line feed ('\n'), a carriage return ('\r'), or a carriage return* followed immediately by a linefeed.** @return A String containing the contents of the line, not including* any line-termination characters, or null if the end of the* stream has been reached** @exception IOException If an I/O error occurs** @see java.nio.file.Files#readAllLines*/public String readLine() throws IOException {return readLine(false);}
类似的还有RandomAccessFile的readLine():
/*** Reads the next line of text from this file. This method successively* reads bytes from the file, starting at the current file pointer,* until it reaches a line terminator or the end* of the file. Each byte is converted into a character by taking the* byte's value for the lower eight bits of the character and setting the* high eight bits of the character to zero. This method does not,* therefore, support the full Unicode character set.** <p> A line of text is terminated by a carriage-return character* ({@code '\u005Cr'}), a newline character ({@code '\u005Cn'}), a* carriage-return character immediately followed by a newline character,* or the end of the file. Line-terminating characters are discarded and* are not included as part of the string returned.** <p> This method blocks until a newline character is read, a carriage* return and the byte following it are read (to see if it is a newline),* the end of the file is reached, or an exception is thrown.** @return the next line of text from this file, or null if end* of file is encountered before even one byte is read.* @exception IOException if an I/O error occurs.*/public final String readLine() throws IOException {StringBuffer input = new StringBuffer();int c = -1;boolean eol = false;while (!eol) {switch (c = read()) {case -1:case '\n':eol = true;break;case '\r':eol = true;long cur = getFilePointer();if ((read()) != '\n') {seek(cur);}break;default:input.append((char)c);break;}}if ((c == -1) && (input.length() == 0)) {return null;}return input.toString();}
转载于:https://www.cnblogs.com/datamining-bio/p/10465631.html
客户端与服务器之间通信收不到信息——readLine()相关推荐
- 客户端和服务器之间通信讲解
原文网址:http://www.myexception.cn/program/1600316.html 一.关键词解释 客户端:能向服务器发送信息,提出请求. 服务器:能接收客户端发来的请求,并能发送 ...
- 客户端和服务器之间的信息结构,客户端与服务器之间的通信过程
客户端与服务器之间的通信过程 内容精选 换一换 一.HTTP概念超文本传输协议(HTTP,HyperTextTransferProtocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必 ...
- 客户端与服务器之间的通信过程
客户端与服务器之间的通信过程主要分为三步:请求--处理--响应 1.客户端发起请求 2.服务器处理本次请求 3.服务器响应客户端
- 客户端到服务器的通信过程
客户端到服务器的通信过程 认识socket socket的英文原意为:孔.插座.当然作为进程通信机制,取插座的意思.通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄 ...
- GBASE 8s客户端与服务器的通信
GBase客户端与服务器的通信支持多种不同的方式:共享内存 Shared memory.Stream pipe. TCP/IP(Sockets.TLI).IPX/SPX.DRDA.我们通常选择TCP/ ...
- 利用Socket 本地和服务器之间通信(小白萌新适用之绝对能运行版)
Java利用Socket 实现本地和服务器之间通信(小白萌新适用之绝对能运行版) 常规部署 1.先在自己本地跑通 客户端: Socket s = new Socket("localhost& ...
- 服务器如何做中转进行端口映射,使服务器之间通信,然后访问目标网站(baidu.com)
文章目录 服务器如何做中转进行端口映射,使服务器之间通信,然后访问目标网站(baidu.com) 问题缘由 所需环境 操作步骤 1. 目的服务器设置 2. 中间服务器设置 3. 修改客户端 总结 服务 ...
- 客户端和服务器之间的信息结构,客户端和服务器之间的信息结构
客户端和服务器之间的信息结构 内容精选 换一换 说明:Web Service客户端和服务器间使用相同的编码方式,是为了防止出现乱码现象,也是实施输入校验的基础.安全加固:web server响应消息统 ...
- 使用sftp在客户端与服务器之间进行文件传输
知识点:sftp 步骤: 一. 登录服务器 使用命令格式:sftp 服务器主机名 二. 在客户端与服务器之间进行文件传输 命令put: 上传到服务器 put haha.txt 命令get: 下载到客户 ...
最新文章
- 【C#实践】三层:初识
- 100% .NET Control_使用CurrencyManager 创建一个导航条来控制DatagGrid的XNavBar控件(VB.NET)....
- 云计算简介+云计算建站平台
- 图像及其表达与性质(上)
- EF通用数据层封装类(支持读写分离,一主多从)
- Java时间日期的处理
- replace使用案例--替换空格
- 使用PostgREST的RestAPI操作之安装教程
- Hibernate简单的保存操作
- 开源BT磁力搜索引擎收集
- 机器人教练SWOT分析_我国工业机器人产业发展的SWOT分析
- 单片机内存及运行原理
- 面试官嘲笑我,这你都不会?
- 百度网盘linux版本怎么安装
- SWAN测试用例botan/net2net-ed25519
- 本地电脑与远程服务器之间无法复制粘贴解决方法
- 崔健没变,北汽极狐该做出改变了
- 压缩算法比较: Gzip vs Bzip2 vs LZMA vs XZ vs LZ4 vs LZO
- gohttp断点续传文件服务器,go文件断点续传功能
- Linux内核进程管理实时调度与SMP
热门文章
- 将您的SQL Server工作负载迁移到PostgreSQL –第2部分
- Bootstrap 公布长期支持计划,Bootstrap 3 生命周期结束
- c# —— 枚举和值的隐藏副作用
- java虚拟机相同吗_Java虚拟机是否真的是与VMWare或Parallels文件相同的虚拟机?
- python 两点曲线_python机器学习分类模型评估
- predict函数 R_RROC三剑客(一)使用R语言手撕ROC曲线
- 数据库和python的结合_redis数据库及与python交互用法简单示例
- js 将多个对象合并成一个对象 assign方法
- mysql 5.7 my default_Windows64位mysql5.7以上版本包解压中没有data目录和my-default.ini及服务无法启动的快速解决办法(问题小结)...
- linux lsof 端口 字母,linux lsof/netstat查看进程和端口号相关命令: