本文整理匯總了Golang中github.com/funny/link.Session.Conn方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Conn方法的具體用法?Golang Session.Conn怎麽用?Golang Session.Conn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/funny/link.Session
的用法示例。
在下文中一共展示了Session.Conn方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleMsgServerClient
func (self *Manager) handleMsgServerClient(msc *link.Session) {
msc.ReadLoop(func(msg link.InBuffer) {
glog.Info("msg_server", msc.Conn().RemoteAddr().String(), "say:", string(msg.Get()))
self.parseProtocol(msg.Get(), msc)
})
}
示例2: connectTransferServer
//其他客戶端連接TransferServer處理
func connectTransferServer(session *link.Session, protoMsg systemProto.ProtoMsg) {
rev_msg := protoMsg.Body.(*systemProto.System_ConnectTransferServerC2S)
serverName := rev_msg.GetServerName()
INFO(serverName + " Connect TransferServer")
useServerName := strings.Split(serverName, "[")[0]
sessions, exists := servers[useServerName]
if !exists {
sessions = make([]*link.Session, 0, 10)
}
sessions = append(sessions, session)
servers[useServerName] = sessions
//GameServer可以有多個
if useServerName == "GameServer" {
addr := strings.Split(session.Conn().RemoteAddr().String(), ":")
addrIp := addr[0]
addrPort, _ := strconv.Atoi(addr[1])
gameConsistent.Add(hashs.NewNode(len(sessions), addrIp, addrPort, serverName, 1))
}
send_msg := systemProto.MarshalProtoMsg(&systemProto.System_ConnectTransferServerS2C{})
systemProto.Send(send_msg, session)
startDealReceiveMsgC2S(session)
}
示例3: getFile
///============================
///消費者 獲取圖片
func getFile(session *link.Session, req map[string]string) error {
seq := req["seq"]
//死等
vf := QueueInstance.DeChan()
if vf == nil {
ULogger.Error("getfile time out,sessioninfo is %s", session.State.(*User).Id)
ret := map[string]string{
"action": "res_getfile",
"seq": seq,
}
by, _ := json.Marshal(ret)
session.Send(link.Bytes(by))
ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
return nil
}
vf.C = session
vf.CInfo = session.State.(*User).Id
vf.Status = 2
vf.CGetUnix = time.Now().Unix()
ret := map[string]string{
"action": "res_getfile",
"seq": seq,
"id": vf.Id,
"file": vf.File,
}
by, _ := json.Marshal(ret)
VFMapInstance.Update("c_getfile", vf)
session.Send(link.Bytes(by))
ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
return nil
}
示例4: SetClientSessionOnline
//LoginServer用戶上線
func SetClientSessionOnline(userSession *link.Session) {
//發送用戶上線消息到serverName
protoMsg := &systemProto.System_ClientSessionOnlineC2S{
SessionID: protos.Uint64(userSession.Id()),
Network: protos.String(userSession.Conn().RemoteAddr().Network()),
Addr: protos.String(userSession.Conn().RemoteAddr().String()),
}
send_msg := protos.MarshalProtoMsg(protoMsg)
sendSystemMsg2("LoginServer", 0, send_msg)
}
示例5: SetClientLoginSuccess
//通知GameServer用戶登錄成功
func SetClientLoginSuccess(userName string, userID uint64, session *link.Session) {
send_msg := protos.MarshalProtoMsg(&systemProto.System_ClientLoginSuccessC2S{
UserID: protos.Uint64(userID),
UserName: protos.String(userName),
SessionID: protos.Uint64(session.Id()),
GameServerID: protos.Uint32(0),
Network: protos.String(session.Conn().RemoteAddr().Network()),
Addr: protos.String(session.Conn().RemoteAddr().String()),
})
sendSystemMsgToServer(send_msg)
}
示例6: connectTransferServer
//其他客戶端連接TransferServer處理
func connectTransferServer(session *link.Session, protoMsg protos.ProtoMsg) {
rev_msg := protoMsg.Body.(*systemProto.System_ConnectTransferServerC2S)
serverName := rev_msg.GetServerName()
serverID := rev_msg.GetServerID()
useServerName := strings.Split(serverName, "[")[0]
serverList, exists := servers[useServerName]
if !exists {
serverList = make([]Server, 0, 10)
}
server := Server{
session: session,
serverID: serverID,
serverIndex: len(serverList),
}
serverList = append(serverList, server)
servers[useServerName] = serverList
//服務器斷開連接處理
session.AddCloseCallback(session, func() {
serverList = append(serverList[:server.serverIndex], serverList[server.serverIndex+1:]...)
servers[useServerName] = serverList
ERR(serverName + " Disconnect At " + global.ServerName)
})
//GameServer可以有多個
if useServerName == "GameServer" {
addr := strings.Split(session.Conn().RemoteAddr().String(), ":")
addrIp := addr[0]
addrPort, _ := strconv.Atoi(addr[1])
gameNode := hashs.NewNode(server.serverIndex, addrIp, addrPort, serverName, 1)
gameConsistent.Add(gameNode)
//GameServer斷開連接處理
session.AddCloseCallback(session, func() {
//移除此Node
gameConsistent.Remove(gameNode)
//將此Node的所有用戶斷開連接
for clientSessionID, gameNodeIndex := range gameUserSessions {
if server.serverIndex == gameNodeIndex {
clientSession := global.GetSession(clientSessionID)
if clientSession != nil {
clientSession.Close()
}
}
}
})
}
//發送連接成功消息
send_msg := protos.MarshalProtoMsg(&systemProto.System_ConnectTransferServerS2C{})
protos.Send(session, send_msg)
}
示例7: AddClient
func (flink *frontendLink) AddClient(session *link.Session) {
flink.clientMutex.Lock()
defer flink.clientMutex.Unlock()
flink.clientWaitId += 1
flink.clientWaits[flink.clientWaitId] = session
addr := session.Conn().RemoteAddr()
flink.session.Send(&gatewayMsg{
Command: CMD_NEW_1, ClientId: flink.clientWaitId,
Data: []byte(addr.Network() + "," + addr.String()),
})
}
示例8: putFile
///======================================
///生產者 ,產生圖驗圖片
func putFile(session *link.Session, req map[string]string) error {
file := req["file"]
seq := req["seq"]
fileid := GetMd5String(file)
vf := &VerifyObj{Id: getId(), P: session, C: nil, FileId: fileid, File: file, Status: 1, Result: "0", Seq: seq, PPutUnix: time.Now().Unix()}
QueueInstance.Enqueue(vf)
VFMapInstance.Put(vf)
ULogger.Infof("putfile 進隊列 %v\n", vf)
//記錄p端的操作
if session.State == nil {
userId := session.Conn().RemoteAddr().String()
user := &User{UserType: "P", Id: userId, WorkTime: time.Now().Format("2006-01-02 15:04:05")}
session.State = user
Exec(`insert into user_activities(user_id,active_time,active_type,user_type,other_info) values(?,now(),'begin','production',?)`, userId, userId)
}
return nil
}
示例9: Process
func Process(session *link.Session, req map[string]string) error {
command, ok := req["action"]
if !ok {
ULogger.Error("client", session.Conn().RemoteAddr().String(), "bad request ,not found action")
session.Close()
return nil
}
if (command == "getfile" || command == "answer") && session.State == nil {
ULogger.Error("client", session.Conn().RemoteAddr().String(), "c must login frist")
session.Close()
return nil
}
switch command {
//p
case "putfile":
return putFile(session, req)
case "reportanswer":
return reportAnswer(session, req)
//c
case "getfile":
return getFile(session, req)
case "cstart":
return cStart(session, req)
case "answer":
return answer(session, req)
default:
ULogger.Error("client", session.Conn().RemoteAddr().String(), "not support command")
session.Close()
//ULogger.Info("sssss")
}
return nil
}
示例10: cStart
///c端開始答題
func cStart(session *link.Session, req map[string]string) error {
userid := req["userid"]
password := req["password"]
seq := req["seq"]
ULogger.Infof("user %s start answer", userid)
ret := map[string]string{
"action": "res_cstart",
"seq": seq,
"result": "0",
}
if session.State != nil && session.State.(*User).UserType == "C" {
ULogger.Error("have logined ", userid)
session.Close()
}
if b := Login(userid, password); !b {
ULogger.Errorf("cstart failed ,userid is %s password is %s", userid, password)
by, _ := json.Marshal(ret)
session.Send(link.Bytes(by))
ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
session.Close()
return nil
} else {
user := &User{UserType: "C", Id: userid, WorkTime: time.Now().Format("2006-01-02 15:04:05")}
session.State = user
ret["result"] = "1"
by, _ := json.Marshal(ret)
session.Send(link.Bytes(by))
ULogger.Info("send to client", session.Conn().RemoteAddr().String(), "say:", string(by))
//c端開始答題
Exec(`insert into user_activities(user_id,active_time,active_type,user_type,other_info) values(?,now(),'begin','customer',?)`, userid, session.Conn().RemoteAddr().String())
VFMapInstance.AddSession(session)
}
return nil
}