Commit 3f1efa5c by zhangjiec

模拟电话机硬件

parents
# 默认忽略的文件
/shelf/
/workspace.xml
# 数据源本地存储已忽略文件
/dataSources/
/dataSources.local.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/devphone10.iml" filepath="$PROJECT_DIR$/.idea/devphone10.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
package dcphone10
import (
"devphone10/jeffutil"
"fmt"
"net"
"time"
)
var TotalConnectErr = 0
var TotalSendErr = 0
var myDevType byte = 0x5A
// 连上服务器,然后每分钟发状态心跳
func TcpConnect(serverAddr string, myDevID uint32) {
conn, err := net.Dial("tcp", serverAddr)
if err != nil {
TotalConnectErr++
fmt.Println(myDevID, TotalConnectErr, "-connect err:", err)
return
}
defer conn.Close()
for {
if err2 := upHeartStatus(conn, myDevID); err2 != nil {
TotalSendErr++
fmt.Println(myDevID, TotalSendErr, "-send err:", err)
break
}
time.Sleep(time.Minute)
}
}
func getOneCiphertext(myDevID uint32, ctrlCode byte, data []byte) []byte {
cleartext := make([]byte, len(data)+12)
nowTimeUtc := uint32(time.Now().Unix())
cleartext[0] = byte(nowTimeUtc)
cleartext[1] = byte(nowTimeUtc >> 8)
cleartext[2] = byte(nowTimeUtc >> 16)
cleartext[3] = byte(nowTimeUtc >> 24)
cleartext[4] = myDevType
cleartext[5] = byte(myDevID)
cleartext[6] = byte(myDevID >> 8)
cleartext[7] = byte(myDevID >> 16)
cleartext[8] = ctrlCode
cleartext[9] = byte(len(data))
copy(cleartext[10:], data)
jeffutil.GetCRC(cleartext, len(data)+10)
return jeffutil.EncryptBytesToBase64(cleartext, "DCRYM-2018-pswd.", "I can't tell YOU")
}
//
func upHeartStatus(conn net.Conn, myDevID uint32) error {
data := make([]byte, 3)
data[0] = 30
data[1] = 31
data[2] = 9
sendData := getOneCiphertext(myDevID, 0x41, data)
sendData[0] = '{'
sendData[len(sendData)-1] = '}'
_, err1 := conn.Write(sendData)
if err1 != nil {
return err1
}
buf := make([]byte, 100)
conn.SetReadDeadline(time.Now().Add(3 * time.Second))
/*cnt*/ _, err := conn.Read(buf)
if err != nil {
fmt.Printf("接收服务器响应心跳失败-------")
return err
}
// todo 处理服务器响应
//if cnt != 8 || string(buf[:cnt]) != "jefftest" {
// arr := strings.Split(string(buf[:cnt]),"jefftest")
// for _,value := range arr{
// if len(value)>0 {
// fmt.Printf("client%d:接收到非握手数据:%s\n", i+1, value)
// }
// }
//}
return nil
}
func UserGetFamilyNum() {
}
func UserGetFamilyMsg() {
}
module "devphone10"
\ No newline at end of file
package jeffutil
// 全角转换半角
func DBCtoSBC(s string) string {
retstr := ""
for _, i := range s {
inside_code := i
if inside_code == 12288 {
inside_code = 32
} else {
inside_code -= 65248
}
if inside_code < 32 || inside_code > 126 {
retstr += string(i)
} else {
retstr += string(inside_code)
}
}
return retstr
}
//import (
// "sort"
// "strings"
//)
//
//type dict struct {
// x, y rune
//}
//
//var toSBC = []dict{
// {0x00A2, 0xFFE0},
// {0x00A3, 0xFFE1},
// {0x00A5, 0xFFE5},
// {0x00A6, 0xFFE4},
// {0x00AC, 0xFFE2},
// {0x00AF, 0xFFE3},
// {0xFF61, 0x3002},
// {0xFF62, 0x300C},
// {0xFF63, 0x300D},
// {0xFF64, 0x3001},
// {0xFF65, 0x30FB},
// {0xFF66, 0x30F2},
// {0xFF67, 0x30A1},
// {0xFF68, 0x30A3},
// {0xFF69, 0x30A5},
// {0xFF6A, 0x30A7},
// {0xFF6B, 0x30A9},
// {0xFF6C, 0x30E3},
// {0xFF6D, 0x30E5},
// {0xFF6E, 0x30E7},
// {0xFF6F, 0x30C3},
// {0xFF70, 0x30FC},
// {0xFF71, 0x30A2},
// {0xFF72, 0x30A4},
// {0xFF73, 0x30A6},
// {0xFF74, 0x30A8},
// {0xFF75, 0x30AA},
// {0xFF76, 0x30AB},
// {0xFF77, 0x30AD},
// {0xFF78, 0x30AF},
// {0xFF79, 0x30B1},
// {0xFF7A, 0x30B3},
// {0xFF7B, 0x30B5},
// {0xFF7C, 0x30B7},
// {0xFF7D, 0x30B9},
// {0xFF7E, 0x30BB},
// {0xFF7F, 0x30BD},
// {0xFF80, 0x30BF},
// {0xFF81, 0x30C1},
// {0xFF82, 0x30C4},
// {0xFF83, 0x30C6},
// {0xFF84, 0x30C8},
// {0xFF85, 0x30CA},
// {0xFF86, 0x30CB},
// {0xFF87, 0x30CC},
// {0xFF88, 0x30CD},
// {0xFF89, 0x30CE},
// {0xFF8A, 0x30CF},
// {0xFF8B, 0x30D2},
// {0xFF8C, 0x30D5},
// {0xFF8D, 0x30D8},
// {0xFF8E, 0x30DB},
// {0xFF8F, 0x30DE},
// {0xFF90, 0x30DF},
// {0xFF91, 0x30E0},
// {0xFF92, 0x30E1},
// {0xFF93, 0x30E2},
// {0xFF94, 0x30E4},
// {0xFF95, 0x30E6},
// {0xFF96, 0x30E8},
// {0xFF97, 0x30E9},
// {0xFF98, 0x30EA},
// {0xFF99, 0x30EB},
// {0xFF9A, 0x30EC},
// {0xFF9B, 0x30ED},
// {0xFF9C, 0x30EF},
// {0xFF9D, 0x30F3},
// {0xFF9E, 0x309B},
// {0xFF9F, 0x309C},
// {0xFFA0, 0x3164},
// {0xFFC2, 0x314F},
// {0xFFC3, 0x3150},
// {0xFFC4, 0x3151},
// {0xFFC5, 0x3152},
// {0xFFC6, 0x3153},
// {0xFFC7, 0x3154},
// {0xFFCA, 0x3155},
// {0xFFCB, 0x3156},
// {0xFFCC, 0x3157},
// {0xFFCD, 0x3158},
// {0xFFCE, 0x3159},
// {0xFFCF, 0x315A},
// {0xFFD2, 0x315B},
// {0xFFD3, 0x315C},
// {0xFFD4, 0x315D},
// {0xFFD5, 0x315E},
// {0xFFD6, 0x315F},
// {0xFFD7, 0x3160},
// {0xFFDA, 0x3161},
// {0xFFDB, 0x3162},
// {0xFFDC, 0x3163},
// {0xFFE8, 0x2502},
// {0xFFE9, 0x2190},
// {0xFFEA, 0x2191},
// {0xFFEB, 0x2192},
// {0xFFEC, 0x2193},
// {0xFFED, 0x25A0},
// {0xFFEE, 0x25CB},
//}
//
//var toDBC = []dict{
// {0x2190, 0xFFE9},
// {0x2191, 0xFFEA},
// {0x2192, 0xFFEB},
// {0x2193, 0xFFEC},
// {0x3000, 0x0020},
// {0x3001, 0xFF64},
// {0x3002, 0xFF61},
// {0x300C, 0xFF62},
// {0x300D, 0xFF63},
// {0x309B, 0xFF9E},
// {0x309C, 0xFF9F},
// {0x30A1, 0xFF67},
// {0x30A2, 0xFF71},
// {0x30A3, 0xFF68},
// {0x30A4, 0xFF72},
// {0x30A5, 0xFF69},
// {0x30A6, 0xFF73},
// {0x30A7, 0xFF6A},
// {0x30A8, 0xFF74},
// {0x30A9, 0xFF6B},
// {0x30AA, 0xFF75},
// {0x30AB, 0xFF76},
// {0x30AD, 0xFF77},
// {0x30AF, 0xFF78},
// {0x30B1, 0xFF79},
// {0x30B3, 0xFF7A},
// {0x30B5, 0xFF7B},
// {0x30B7, 0xFF7C},
// {0x30B9, 0xFF7D},
// {0x30BB, 0xFF7E},
// {0x30BD, 0xFF7F},
// {0x30BF, 0xFF80},
// {0x30C1, 0xFF81},
// {0x30C3, 0xFF6F},
// {0x30C4, 0xFF82},
// {0x30C6, 0xFF83},
// {0x30C8, 0xFF84},
// {0x30CA, 0xFF85},
// {0x30CB, 0xFF86},
// {0x30CC, 0xFF87},
// {0x30CD, 0xFF88},
// {0x30CE, 0xFF89},
// {0x30CF, 0xFF8A},
// {0x30D2, 0xFF8B},
// {0x30D5, 0xFF8C},
// {0x30D8, 0xFF8D},
// {0x30DB, 0xFF8E},
// {0x30DE, 0xFF8F},
// {0x30DF, 0xFF90},
// {0x30E0, 0xFF91},
// {0x30E1, 0xFF92},
// {0x30E2, 0xFF93},
// {0x30E3, 0xFF6C},
// {0x30E4, 0xFF94},
// {0x30E5, 0xFF6D},
// {0x30E6, 0xFF95},
// {0x30E7, 0xFF6E},
// {0x30E8, 0xFF96},
// {0x30E9, 0xFF97},
// {0x30EA, 0xFF98},
// {0x30EB, 0xFF99},
// {0x30EC, 0xFF9A},
// {0x30ED, 0xFF9B},
// {0x30EF, 0xFF9C},
// {0x30F2, 0xFF66},
// {0x30F3, 0xFF9D},
// {0x30FB, 0xFF65},
// {0x30FC, 0xFF70},
// {0x314F, 0xFFC2},
// {0x3150, 0xFFC3},
// {0x3151, 0xFFC4},
// {0x3152, 0xFFC5},
// {0x3153, 0xFFC6},
// {0x3154, 0xFFC7},
// {0x3155, 0xFFCA},
// {0x3156, 0xFFCB},
// {0x3157, 0xFFCC},
// {0x3158, 0xFFCD},
// {0x3159, 0xFFCE},
// {0x315A, 0xFFCF},
// {0x315B, 0xFFD2},
// {0x315C, 0xFFD3},
// {0x315D, 0xFFD4},
// {0x315E, 0xFFD5},
// {0x315F, 0xFFD6},
// {0x3160, 0xFFD7},
// {0x3161, 0xFFDA},
// {0x3162, 0xFFDB},
// {0x3163, 0xFFDC},
// {0x3164, 0xFFA0},
// {0xFF5F, 0x2985},
// {0xFF60, 0x2986},
// {0xFFE0, 0x00A2},
// {0xFFE1, 0x00A3},
// {0xFFE2, 0x00AC},
// {0xFFE3, 0x00AF},
// {0xFFE4, 0x00A6},
// {0xFFE5, 0x00A5},
// {0xFFE6, 0x20A9},
//}
//
//// 从strings包拷贝,因此不必导入strings包即可使用本函数。
//var Map = strings.Map
//
//// 判断一个字符是否是半角字符
//func IsSBC(c rune) bool {
// switch {
// case c <= 0x007E:
// case c == 0x00A2 || c == 0x00A3:
// case c == 0x00A5 || c == 0x00A6:
// case c == 0x00AC || c == 0x00AF:
// case c == 0x20A9:
// case c == 0x2985 || c == 0x2986:
// case c >= 0xFF61 && c <= 0xFF9F:
// case c >= 0xFFA0 && c <= 0xFFBE:
// case c >= 0xFFC2 && c <= 0xFFC7:
// case c >= 0xFFCA && c <= 0xFFCF:
// case c >= 0xFFD2 && c <= 0xFFD7:
// case c >= 0xFFDA && c <= 0xFFDC:
// case c >= 0xFFE8 && c <= 0xFFEE:
// default:
// return false
// }
// return true
//}
//
//// 如果字符c为全角字符,返回对应半角字符(如有);否则返回c。
//func ToDBC(c rune) rune {
// switch {
// case c <= 0x218F:
// return c
// case c <= 0x2193:
// case c == 0x2502:
// return 0xFFE8
// case c == 0x25A0:
// return 0xFFED
// case c == 0x25CB:
// return 0xFFEE
// case c <= 0x2FFF:
// return c
// case c <= 0x30FC:
// case c <= 0x3130:
// return c
// case c <= 0x314E:
// return c + 0xCE70
// case c <= 0x3164:
// case c <= 0xFF00:
// return c
// case c <= 0xFF5E:
// return c - 0xFEE0
// case c >= 0xFFE7:
// return c
// }
// i := sort.Search(len(toDBC), func(i int) bool { return toDBC[i].x >= c })
// if toDBC[i].x == c {
// return toDBC[i].y
// } else {
// return c
// }
//}
//
//// 如果字符c为半角字符,返回对应全角字符(如有);否则返回c。
//func ToSBC(c rune) rune {
// switch {
// case c <= 0x001F:
// return c
// case c == 0x0020:
// return 0x3000
// case c <= 0x007E:
// return c + 0xFEE0
// case c <= 0x00AF:
// case c == 0x20A9:
// return 0xFFE6
// case c == 0x2985:
// return 0xFF5F
// case c == 0x2986:
// return 0xFF60
// case c <= 0xFF60:
// return c
// case c <= 0xFFA0:
// case c <= 0xFFBE:
// return c - 0xCE70
// case c >= 0xFFEF:
// return c
// }
// i := sort.Search(len(toSBC), func(i int) bool { return toSBC[i].x >= c })
// if toSBC[i].x == c {
// return toSBC[i].y
// } else {
// return c
// }
//}
//
//// 如果字符c为全角ASCII字符,返回对应的半角字符;否则返回c。
//func ToASCIIDBC(r rune) rune {
// if r == 0x3000 {
// return 0x3000
// }
// if r >= 0xFF01 && r <= 0xFF5E {
// return r - 0xFEE0
// }
// return r
//}
//
//// 如果字符c为半角ASCII字符,返回对应的全角字符;否则返回c。
//func ToASCIISBC(r rune) rune {
// if r == 0x0020 {
// return 0x3000
// }
// if r >= 0x0021 && r <= 0x007E {
// return r + 0xFEE0
// }
// return r
//}
package jeffutil
func CheckCRC(buf []byte) bool {
var wCrcData uint16 = 0xffff
for _, v := range buf {
wCrcData ^= uint16(v)
for j := 0; j < 8; j++ {
if wCrcData&1 != 0 {
wCrcData >>= 1
wCrcData ^= 0xa001
} else {
wCrcData >>= 1
}
}
}
return wCrcData == 0
}
// GetCRC 获取2个字节的CRC16
func GetCRC(buf []byte, len int) { //传入的切片必须装得下
var wCrcData uint16 = 0xffff
for i := 0; i < len; i++ {
wCrcData ^= uint16(buf[i])
for j := 0; j < 8; j++ {
if wCrcData&1 != 0 {
wCrcData >>= 1
wCrcData ^= 0xa001
} else {
wCrcData >>= 1
}
}
}
buf[len] = byte(wCrcData)
buf[len+1] = byte(wCrcData >> 8)
}
package jeffutil
import (
"encoding/base64"
"errors"
)
func EncryptBytesToBase64(cleartext []byte, pswd string, iv string) (base64Result []byte) { //看base64库,返回切片更快,本来tcp发送也是切片,不过这里面string也是切片
var pswdIv [16]byte
var pswdSum byte
var i int
cleartextLen := len(cleartext)
var result = make([]byte, cleartextLen+1)
for i = 0; i < 16; i++ {
pswdIv[i] = ((pswd[i] & 0xaa) | (pswd[15-i] & 0x55)) + iv[15-i] + byte(i)
if i%2 == 0 {
pswdSum += pswd[i] + iv[i]
} else {
pswdSum -= pswd[i] - iv[i]
}
}
for i = 0; i < 16; i++ {
if i%2 == 0 {
pswdIv[i] = ^pswdIv[i] + pswdSum
} else {
pswdIv[i] = pswdIv[i] - ^pswdSum
}
}
result[cleartextLen] = ^pswdSum
for i = 0; i < cleartextLen; i++ {
result[cleartextLen] += cleartext[i]
}
for i = 0; i < cleartextLen; i++ {
result[i] = ^((cleartext[i] & 0x72) | (cleartext[cleartextLen-1-i] & 0x8d))
if i%2 == 0 {
result[i] += pswdIv[i%16] - result[cleartextLen]
} else {
result[i] -= pswdIv[i%16] + result[cleartextLen]
}
}
base64Result = make([]byte, base64.StdEncoding.EncodedLen(cleartextLen+1)+2) //多出两个用来装起始结束符
base64.StdEncoding.Encode(base64Result[1:], result)
return
//return base64.StdEncoding.EncodeToString(result)
}
// DecryptBase64ToBytes 解密并转换为bytes
func DecryptBase64ToBytes(ciphertext []byte, pswd string, iv string) ([]byte, error) { //看base64库,传入切片更快,本来tcp接收也是切片,不过这里面string也是切片
var pswdIv [16]byte
var pswdSum byte
var i int
cipherBytes := make([]byte, base64.StdEncoding.DecodedLen(len(ciphertext)))
hexLen, err := base64.StdEncoding.Decode(cipherBytes, ciphertext)
//cipherBytes, err := base64.StdEncoding.DecodeString(ciphertext)
if err != nil {
return nil, err
}
clearLen := hexLen - 1
var resultBytes = make([]byte, clearLen)
var resultBytesTemp = make([]byte, clearLen)
for i = 0; i < 16; i++ {
pswdIv[i] = ((pswd[i] & 0xaa) | (pswd[15-i] & 0x55)) + iv[15-i] + byte(i)
if i%2 == 0 {
pswdSum += pswd[i] + iv[i]
} else {
pswdSum -= pswd[i] - iv[i]
}
}
for i = 0; i < 16; i++ {
if i%2 == 0 {
pswdIv[i] = ^pswdIv[i] + pswdSum
} else {
pswdIv[i] = pswdIv[i] - ^pswdSum
}
}
for i = 0; i < clearLen; i++ {
if i%2 == 0 {
resultBytesTemp[i] = ^(cipherBytes[i] - (pswdIv[i%16] - cipherBytes[clearLen]))
} else {
resultBytesTemp[i] = ^(cipherBytes[i] + (pswdIv[i%16] + cipherBytes[clearLen]))
}
}
var sum byte
for i = 0; i < clearLen; i++ {
resultBytes[i] = (resultBytesTemp[i] & 0x72) | (resultBytesTemp[clearLen-1-i] & 0x8d)
sum += resultBytes[i]
}
sum += ^pswdSum
if sum != cipherBytes[clearLen] {
return nil, errors.New("密文校验错误")
}
return resultBytes, nil
}
package jeffutil
import (
"fmt"
"testing"
)
//测试用例文件使用 go test 指令来执行,没有也不需要 main() 作为函数入口
//所有在以_test结尾的源码内以Test开头的函数会自动被执行。
func TestHex2Cipher(t *testing.T) {
a := "abcABC哈哈哈就glad就是理工科,的垃圾疯狂的建安费、放大算法。dfafajdf!!"
fmt.Println(a)
fmt.Println(DBCtoSBC(a))
//password := "DCRYM-2018-pswd."
//iv := "I can't tell YOU"
//
//type HexData struct {
// TimeUtc uint32
// DevType uint8
// DevID uint32
// CtrlCode uint8
// Length uint8
// Data []byte
//}
//sData := HexData{
// 1626766761,
// 0x3E,
// 0x000001,
// 0x41,
// 201,//15,
// []byte{
// 0, //通讯延迟
// 0x00, //状态码
// 0x01,0x00, //左电流
// 0x02,0x00, //右电流
// 0x03,0x00, //左电阻
// 0x04,0x00, //右电阻
// 0x05, //左温度
// 0x06, //右温度
// 0x07, //VCC_H
// 0x08, //VCC_L
// 0, //正在使用的用户数
// },
//}
//sData.Length = 243 // 255 267 362 // 243 255 346
//fmt.Println("sData.Length:",sData.Length)
//hexBuf := make([]byte, int(sData.Length) + 12)
//hexBuf[0] = byte(sData.TimeUtc >> 24)
//hexBuf[1] = byte(sData.TimeUtc >> 16)
//hexBuf[2] = byte(sData.TimeUtc >> 8)
//hexBuf[3] = byte(sData.TimeUtc)
//hexBuf[4] = sData.DevType
//hexBuf[5] = byte(sData.DevID >> 16)
//hexBuf[6] = byte(sData.DevID >> 8)
//hexBuf[7] = byte(sData.DevID)
//hexBuf[8] = sData.CtrlCode
//hexBuf[9] = sData.Length
//sData.Data = make([]byte,sData.Length)
////if sData.Length>0 {
//copy(hexBuf[10:],sData.Data[:sData.Length])
////}
//fmt.Println("len(hexBuf)",len(hexBuf))
//GetCRC(hexBuf,int(sData.Length)+10)
//sendStr := EncryptBytesToBase64(hexBuf,password,iv)
//
//sendStr[0] = '{'
//sendStr[len(sendStr) - 1] = '}'
//
//fmt.Printf("string(sendStr):%s\nlen:%d\n",string(sendStr),len(sendStr))
}
//func main() {
// a := "4769676162697445746865726E6574302F302F323400"
// bs, err := hex.DecodeString(a)
// if err != nil {
// panic(err)
// }
// fmt.Println(string(bs))
//}
package jeffutil
//import (
// "go.uber.org/zap/zapcore"
// "gopkg.in/ini.v1"
// // "jeff_workstation_1/logger"
// "time"
//)
//
//var (
// HttpServerMode string
// HttpServerPort string
//
// HttpClientBaseUrl string
// HttpClientTimeOut time.Duration
//
// TcpLongPort string
// TcpLongMaxConnections uint16
// TcpLongNewConnReadDeadline time.Duration
// TcpLongNewConnRightfulTimeout int64
// TcpLongOldConnReadDeadline time.Duration
//
// LogLevel zapcore.Level
// LogPath string
// LogFileMaxSize int // 单个日志文件的最大MB
//
// LogInfoMaxFileNum int
// LogInfoMaxFileDay int
//
// LogWarnMaxFileNum int
// LogWarnMaxFileDay int
//
// LogErrorMaxFileNum int
// LogErrorMaxFileDay int
//)
//
//func init() {
// file, err := ini.Load("./config.ini")
// if err != nil {
// // logger.Log.Panic("配置文件读取错误")
// panic("配置文件读取错误")
// }
// HttpServerMode = file.Section("http_server").Key("ServerMode").In("release", []string{"release", "debug"})
// HttpServerPort = file.Section("http_server").Key("ServerPort").MustString(":50000")
//
// HttpClientBaseUrl = file.Section("http_client").Key("ServerPort").MustString("http://handandev.swaylink.cn/phone/2/server/")
// HttpClientTimeOut = time.Duration(file.Section("http_client").Key("TimeOut").MustInt(5)) * time.Second
//
// TcpLongPort = file.Section("tcp_long_server").Key("TcpPort").MustString("60000")
// TcpLongMaxConnections = uint16(file.Section("tcp_long_server").Key("MaxConnections").MustUint(20000))
// TcpLongNewConnReadDeadline = time.Duration(file.Section("tcp_long_server").Key("NewConnReadDeadline").MustInt(60)) * time.Second
// TcpLongNewConnRightfulTimeout = file.Section("tcp_long_server").Key("NewConnRightfulTimeout").MustInt64(120)
// TcpLongOldConnReadDeadline = time.Duration(file.Section("tcp_long_server").Key("OldConnReadDeadline").MustInt(180)) * time.Second
//
// logLvlStr := file.Section("log").Key("Level").In("warn", []string{"trace", "debug", "info", "warn", "error"})
// switch logLvlStr {
// case "debug":
// LogLevel = zapcore.DebugLevel
// case "info":
// LogLevel = zapcore.InfoLevel
// case "warn":
// LogLevel = zapcore.WarnLevel
// case "error":
// LogLevel = zapcore.ErrorLevel
// }
// LogPath = file.Section("log").Key("Path").MustString(".log")
// LogFileMaxSize = file.Section("log").Key("FileMaxSize").MustInt(10)
//
// LogInfoMaxFileNum = file.Section("log").Key("InfoMaxFileNum").MustInt(10)
// LogInfoMaxFileDay = file.Section("log").Key("InfoWithMaxAge").MustInt(30)
//
// LogWarnMaxFileNum = file.Section("log").Key("WarnMaxFileNum").MustInt(10)
// LogWarnMaxFileDay = file.Section("log").Key("WarnWithMaxAge").MustInt(90)
//
// LogErrorMaxFileNum = file.Section("log").Key("ErrorMaxFileNum").MustInt(10)
// LogErrorMaxFileDay = file.Section("log").Key("ErrorWithMaxAge").MustInt(180)
//
// //LogTraceWithRotationTime = time.Duration(file.Section("log").Key("TraceWithRotationTime").MustInt(2)) * time.Hour
// //LogTraceWithMaxAge = time.Duration(file.Section("log").Key("TraceWithMaxAge").MustInt(24)) * time.Hour
// //
// //LogDebugWithRotationTime = time.Duration(file.Section("log").Key("DebugWithRotationTime").MustInt(2)) * time.Hour
// //LogDebugWithMaxAge = time.Duration(file.Section("log").Key("DebugWithMaxAge").MustInt(24)) * time.Hour
// //
// //LogInfoWithRotationTime = time.Duration(file.Section("log").Key("InfoWithRotationTime").MustInt(24)) * time.Hour
// //LogInfoWithMaxAge = time.Duration(file.Section("log").Key("InfoWithMaxAge").MustInt(3*24)) * time.Hour
// //
// //LogWarnWithRotationTime = time.Duration(file.Section("log").Key("WarnWithRotationTime").MustInt(24)) * time.Hour
// //LogWarnWithMaxAge = time.Duration(file.Section("log").Key("WarnWithMaxAge").MustInt(7*24)) * time.Hour
// //
// //LogErrorWithRotationTime = time.Duration(file.Section("log").Key("ErrorWithRotationTime").MustInt(10*24)) * time.Hour
// //LogErrorWithMaxAge = time.Duration(file.Section("log").Key("ErrorWithMaxAge").MustInt(30*24)) * time.Hour
//}
File added
package main
import (
"devphone10/dcphone10"
"fmt"
"time"
)
func main() {
var i uint32
for i = 0; i < 2; i++ {
go dcphone10.TcpConnect("dev.lezhixy.com:4999", i) //i+20000)
time.Sleep(2 * time.Millisecond)
fmt.Println("总连接数", i+1)
}
for {
time.Sleep(2 * time.Second)
fmt.Println("totalConnectErr", dcphone10.TotalConnectErr, "TotalSendErr", dcphone10.TotalSendErr)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment