当前位置:网站首页>970 golang realizes the communication between multithreaded server and client
970 golang realizes the communication between multithreaded server and client
2022-07-02 00:57:00 【-Lin Zeyu】
package main
import (
"net"
"fmt"
"time"
)
func server(){
listen_sock, err := net.Listen("tcp", "0.0.0.0:8888")
if err != nil {
fmt.Println("listen error")
return;
}
defer listen_sock.Close()
conn, err := listen_sock.Accept()
if err != nil {
fmt.Println("accept error")
return;
}
defer conn.Close()
buf := make([]byte, 100)
for(true){
n, err := conn.Read(buf)
if err != nil {
fmt.Println("conn closed")
return
}
fmt.Println("msg size:", n, string(buf[0:n]))
}
}
func client(){
conn, err := net.Dial("tcp", "127.0.0.1:8888")
if err != nil {
fmt.Println("check server")
return
}
defer conn.Close()
for(true){
s := []byte("abc")
conn.Write(s)
time.Sleep(1 * time.Second)
}
}
func main(){
go server()
go client()
time.Sleep(10 * time.Minute)
}
边栏推荐
- Recently, three articles in the nature sub Journal of protein and its omics knowledge map have solved the core problems of biology
- js 公共库 cdn 推荐
- What is ThreadLocal memory leak and how to solve it
- Iclr2022 | spherenet and g-spherenet: autoregressive flow model for 3D molecular graph representation and molecular geometry generation
- 测试人进阶技能:单元测试报告应用指南
- Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
- excel查找与引用函数
- Evolution of Himalayan self-developed gateway architecture
- Kyushu cloud and Intel jointly released the smart campus private cloud framework, enabling new infrastructure for education
- Promise and modular programming
猜你喜欢
![[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)](/img/c2/7ebc67e9b886e3baf3c98489bf9bce.png)
[eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)

AIX存储管理之逻辑卷的创建及属性的查看和修改

Schrodinger's Japanese learning applet source code

2022拼多多详情/拼多多商品详情/拼多多sku详情

Use es to realize epidemic map or take out order function (including code and data)

SSO single sign on implementation.

With the acquisition of Xilinx, AMD is more than "walking on two legs" | Jiazi found

"C zero foundation introduction hundred knowledge hundred examples" (73) anonymous function -- lambda expression

Advanced skills of testers: a guide to the application of unit test reports

Random avatar encyclopedia, multi category wechat applet source code with history_ Support traffic master
随机推荐
[cascade classifier training parameters] training Haar cascades
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Collection: comprehensive summary of storage knowledge
UDS bootloader of s32kxxx bootloader
Global and Chinese markets of edge AI software 2022-2028: Research Report on technology, participants, trends, market size and share
[JS download files through url]
【底部弹出-选择器】uniapp Picker组件——底部弹起的滚动选择器
Global and Chinese market of aircraft MRO software 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 0241.为运算表达式设计优先级 - DFS
2022 operation of simulated examination platform for melting welding and thermal cutting work license
Output results of convolution operation with multiple tensors and multiple convolution kernels
测试员8年工资变动,令网友羡慕不已:你一个月顶我一年工资
How to extract login cookies when JMeter performs interface testing
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
"C zero foundation introduction hundred knowledge hundred examples" (73) anonymous function -- lambda expression
[CTF] bjdctf 2020 Bar _ Bacystack2
How do Lenovo computers connect Bluetooth headsets?
How to type spaces in latex
If the browser is accidentally closed, how does react cache the forms filled out by users?
gradle