推荐一下,准备写一段同样功能的代码比较一下体验
@robertchen</a>
include是有的,是markdown 和 include的尖括号冲突了 改成引号就有了 同时使用格式错乱了 如果同时@会员 和 贴代码 帖子会出现两份内容 同时加一些乱的标签,估计是这个在线编辑器的bug"
#4
更多评论
```
#include "iostream"
#include "boost/asio.hpp"
int main(void) {
boost::asio::io_service ios;
boost::asio::ip::tcp::endpoint endpotion(boost::asio::ip::tcp::v4(), 8080);
boost::asio::ip::tcp::acceptor acceptor(ios, endpotion);
while (true) {
boost::asio::ip::tcp::socket socket(ios);
acceptor.accept(socket);
std::string msg;
socket.read_some(boost::asio::buffer(msg));
std::cout << "client : " << msg.c_str() << std::endl;
socket.write_some(boost::asio::buffer(msg));
}
}
std::cout << "server end." << std::endl;
getchar();
return 0;
}
-------------
package main
import (
"fmt"
"net"
"os"
)
func main() {
netListen, err := net.Listen("tcp", "localhost:8080")
CheckError(err)
defer netListen.Close()
for {
conn, err := netListen.Accept()
if err != nil {
continue
}
handleConnection(conn)
}
}
func handleConnection(conn net.Conn) {
buffer := make([]byte, 2048)
for {
n, err := conn.Read(buffer)
CheckError(err)
fmt.Println("client : ", string(buffer[:n]))
conn.Write(buffer[:n])
}
fmt.Println("server end.")
}
func CheckError(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
os.Exit(1)
}
}
```
#2