Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# go_study
person study
study git
person study
git&&log
8 changes: 4 additions & 4 deletions tcpboxV0.8/Client.go → TcpBox/Client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"io"
"net"
"tcpbox/tcpnet"
"time"
"zinx/znet"
)

func main() {
Expand All @@ -18,8 +18,8 @@ func main() {
defer conn.Close()
for {
//发送封包的msg消息
dp := znet.NewDataPack()
ms := znet.NewMsgPackage(0, []byte("zinx0.5 client test message!"))
dp := tcpnet.NewDataPack()
ms := tcpnet.NewMsgPackage(0, []byte("zinx0.5 client test message!"))
binaryMsg, err := dp.Pack(ms)
if nil != err {
fmt.Println("Pack error:", err)
Expand Down Expand Up @@ -50,7 +50,7 @@ func main() {
}
if msgHead.GetMsgLen() > 0 {
//再根据datalen进行二次读取,将data读出来
msg := msgHead.(*znet.Message)
msg := msgHead.(*tcpnet.Message)
msg.MsgData = make([]byte, msg.GetMsgLen())

if _, err := io.ReadFull(conn, msg.MsgData); nil != err {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tcpboxV0.9/conf/zinx.json → TcpBox/conf/tcpbox.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Name": "ZinxApp",
"Name": "TcpBoxApp",
"Host": "0.0.0.0",
"Version": 0.6,
"IPVersion": "tcp4",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions tcpboxV0.9/tcpnet/connection.go → TcpBox/tcpnet/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Connection struct {
//当前conn隶属于哪个server
TcpServer tcpiface.IServer

//当球按连接的socket
//当前按连接的socket
Conn *net.TCPConn

//连接的ID
Expand All @@ -43,7 +43,7 @@ type Connection struct {
propertyLock sync.RWMutex
}

//初始化链接模块的方法
// 初始化链接模块的方法
func NewConnection(server tcpiface.IServer, conn *net.TCPConn, connID uint32, msgHandler tcpiface.IMsgHandle) *Connection {
c := &Connection{
TcpServer: server,
Expand All @@ -59,7 +59,7 @@ func NewConnection(server tcpiface.IServer, conn *net.TCPConn, connID uint32, ms
return c
}

//链接的读数据方法
// 链接的读数据方法
func (c *Connection) StartReader() {

fmt.Println("Reader goroutine is running...")
Expand Down Expand Up @@ -118,7 +118,7 @@ func (c *Connection) StartReader() {
}
}

//写消息的goroutine,专门将消息发送给客户端的模块
// 写消息的goroutine,专门将消息发送给客户端的模块
func (c *Connection) StartWriter() {
fmt.Println("Writer Goroutine is running!!!")
defer fmt.Println(c.RemoteAddr().String(), "[conn writer exit!]")
Expand All @@ -140,7 +140,7 @@ func (c *Connection) StartWriter() {
}
}

//启动链接,让当前的链接准备工作
// 启动链接,让当前的链接准备工作
func (c *Connection) Start() {

fmt.Println(" Conn Start()... ConnID:", c.ConnID)
Expand All @@ -157,7 +157,7 @@ func (c *Connection) Start() {

}

//停止链接,结束当前链接的工作
// 停止链接,结束当前链接的工作
func (c *Connection) Stop() {

fmt.Println(" Conn Stop()... ConnID:", c.ConnID)
Expand All @@ -184,22 +184,22 @@ func (c *Connection) Stop() {

}

//获取当前链接绑定的socket conn
// 获取当前链接绑定的socket conn
func (c *Connection) GetTCPConnection() *net.TCPConn {
return c.Conn
}

//获取当前连接模块的连接ID
// 获取当前连接模块的连接ID
func (c *Connection) GetConnID() uint32 {
return c.ConnID
}

//获取远程客户端的TCP状态 IP PORT
// 获取远程客户端的TCP状态 IP PORT
func (c *Connection) RemoteAddr() net.Addr {
return c.Conn.RemoteAddr()
}

//发送数据,将数据发送给远程的客户端
// 发送数据,将数据发送给远程的客户端
func (c *Connection) SendMsg(msgID uint32, data []byte) error {
if c.isClosed == true {
return errors.New("Connection closed when send msg")
Expand All @@ -218,7 +218,7 @@ func (c *Connection) SendMsg(msgID uint32, data []byte) error {
return nil
}

//设置连接属性
// 设置连接属性
func (c *Connection) SetProperty(key string, value interface{}) {
c.propertyLock.Lock()
defer c.propertyLock.Unlock()
Expand All @@ -227,7 +227,7 @@ func (c *Connection) SetProperty(key string, value interface{}) {
c.property[key] = value
}

//获取连接属性
// 获取连接属性
func (c *Connection) GetProperty(key string) (interface{}, error) {
c.propertyLock.RLock()
defer c.propertyLock.RUnlock()
Expand All @@ -239,7 +239,7 @@ func (c *Connection) GetProperty(key string) (interface{}, error) {
}
}

//删除连接属性
// 删除连接属性
func (c *Connection) RemoveProperty(key string) {
c.propertyLock.RLock()
defer c.propertyLock.RUnlock()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tcpboxV0.9/utils/globalobj.go → TcpBox/utils/globalobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type GlobalObj struct {

var GlobalObject *GlobalObj

//提供一个init方法,初始化GlobalObject对象
// 提供一个init方法,初始化GlobalObject对象
func init() {
//如果配置文件没有加载,此为默认的配置
GlobalObject = &GlobalObj{
Expand All @@ -63,9 +63,9 @@ func init() {
GlobalObject.Reload()
}

//从zinx.json去加载用户自定义的参数
// 从zinx.json去加载用户自定义的参数
func (g *GlobalObj) Reload() {
data, err := ioutil.ReadFile("./conf/zinx.json")
data, err := ioutil.ReadFile("./conf/tcpbox.json")
if nil != err {
panic("[Reload] Reload failed")
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions demo/redis_test/likui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"context"
"github.com/redis/go-redis/v9"
"log"
"os"
)

func main() {
client := redis.NewClient(&redis.Options{
Addr: "123.249.105.59:6379",
DB: 0,
Password: "950629",
PoolSize: 10,
})
result, err := client.Ping(context.Background()).Result()
if err != nil {
log.Printf("connect to redis failed err:%v", err)
panic("wrong")
}
log.Print(result)
log.SetFlags(log.Ldate | log.Ltime)
log.SetPrefix("[likui]")
log.SetOutput(os.Stdout)
test1(client)
}
func test1(client *redis.Client) {
set := client.Set(context.Background(), "test", "不再喜欢", 0)
log.Printf("operation:%v result:%v", set.String(), set.Val())
get := client.Get(context.Background(), "test")
log.Printf("operation:%v result:%v", get.String(), get.Val())
}
Loading