import java.io.IOException;
/**
* Entry is HTTP Server entry, each socket create a thread
* @author hui.wang
*
*/
public class Entry {
public static void main(String[] args){
try{
Server server = new Server(8080);
server.run();
} catch(IOException e) {
System.err.println("Error binding the specified port.");
}
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
/**
* Service support echo input to output
* @author hui.wang
*
*/
public class Service extends Thread {
private Socket _socket;
public Service(Socket socket) {
_socket = socket;
}
public void run(){
try{
//Wrapper the InputStream to BufferedReader
BufferedReader input = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
//Wrapper the OutputStream to BuffedWriter
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
String line = input.readLine();
while( line != null ) {
if(line.equals("quit"))
return;
output.write(line + "\r\n");
output.flush();
line = input.readLine();
}
input.close();
output.close();
} catch(IOException e){
//Abandon the current connection
} finally{
try{
//Close the connection.
_socket.close();
} catch(IOException e){
//Eat the IOException
}
}
}
}
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* One server instance, create service to execute operation.
* @author hui.wang
*
*/
public class Server implements Runnable {
private ServerSocket _server;
public Server(int port) throws IOException {
// This statement will throw out IOException
// if the specified port is not available.
_server = new ServerSocket(port);
}
public void run() {
try {
for (;;) {
// Accept an incoming connection.
Socket client = _server.accept();
// Create a Service Thread to serve the client.
Service service = new Service(client);
service.start();
}
} catch (IOException e) {
// Eat the IOException
}
}
}
分享到:
相关推荐
asio-1.22.1 + websocketpp-0.8.2 non-boost,不需要boost,编译器需要支持c++11
回声服务器 Java 上的回声服务器 (telnet)
python echo服务器基准使用gevent,龙卷风,twisted,asyncio构建回声服务器,并比较它们的速度。 $sh benchmark.sh>benchmark.log结果在我的计算机上是: c ./server_libev 3100Throughput: 214467.02 [reqests/sec...
回声服务器 实验回显服务器和相应的客户端(C++/WinSock)
回声服务器 Echo Server是一个支持Docker且可扩展的Node.js应用程序,用于托管您自己的Socket.IO服务器以进行Laravel广播。 它建立在Socket.IO之上,并且在下面具有Pusher兼容的API服务器,这使在Laravel中的实现变...
回声服务器在此服务器的任何端点上使用 POST 或 PATCH, 当您稍后使用 GET 调用同一端点时,您将获得原始请求详细信息:标头、正文...存储数据您可以在您想要的任何端点上使用 POST 或 PATCH。 curl \ -XPOST \ -H ...
RFC 6455(所有最新浏览器) TLS / SSL开箱即用通过高速公路Websocket测试套件支持 Python 2 和 3安装 pip install simple-websocket-server回声服务器示例 from simple_websocket_server import WebSocketServer ,...
暴民使用mio async-io库以Rust编写的多回声服务器。 master分支当前已设置为可与mio的master分支配合使用(aka 0.6.0-dev ) 0.5分支是设置到工作靠在0.5 MIO的分支安装运行cargo build来构建mob-server和mob-client...
它在有限区域(例如工作场所、局域网、城域网)中充当回声服务器,用于监视目的。 虽然服务器的基本实现非常有限(基本回显服务器),但这还不是一个完整的版本。第一个版本有什么? 第一个版本(代号为MULTIECHO ...
代理服务器这是作为CodePath要求提交的Node.js代理服务器。 花费时间:4〜5小时完全的...启动服务器npm start特征回声服务器: 上次登录:ttys011 L-SB80XTFFT4-M:proxy-server pwang14 $ curl -v -X POST -d“ hello
基于TCP协议的通信程序,包括Server与Client两个部分。客户端发送消息,服务器端将收到的消息原样会送给客户端。
回声服务器
回声服务器使用Elixir lang的简单回显服务器该回显服务器用于教育目的。 贡献者:奥兰多·努涅斯(ID)1070842
代理服务器 ...回声服务器: L-SB8T2SQG3Q-M:proxy-server xpan2$ curl -v http://127.0.0.1:8000 -d " hello world " -H " x-asdf: foo " * Rebuilt URL to: http://127.0.0.1:8000/ * Hostname was NOT
回声服务器一个响应请求的简单服务器。怎么跑确保已安装node和npm 。 运行npm install安装依赖项。 运行npm start启动服务器。 服务器记录对/端点发出的每个GET和POST请求。 记录的相同对象也作为响应发送。
用Python编写的简单Websocket...回声服务器示例 from SimpleWebSocketServer import SimpleWebSocketServer , WebSocket class SimpleEcho ( WebSocket ): def handleMessage ( self ): # echo message back to clien
这是基于来自类型安全激活器模板 akka-stream-scala 的 TcpEcho(仅限服务器)的回声服务器的实现。 这里的目的是提供一个示例,说明如何使用 FlowGraph DSL 向原始 TcpEcho 服务器添加附加功能。 EchoServer 代码...
Post2Server 将POST数据改造为PHP服务器 文件:index.php 回声json_encode($ _ POST); ?>
Node.js 网络服务器 node.js 项目的简单回声服务器 主分支 回声服务器 日志和调试 登录
回声服务器 代理服务器 日志记录 命令行界面: 允许传入日志文件 允许传入 destinationUrl 和端口 可选的用户故事 进程转发 更好的日志记录(日志级别) 文档 (-h) 支持HTTPS 奖励:为 https 目标端口添加...