本文整理匯總了Golang中github.com/gorilla/websocket.Conn.RemoteAddr方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.RemoteAddr方法的具體用法?Golang Conn.RemoteAddr怎麽用?Golang Conn.RemoteAddr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gorilla/websocket.Conn
的用法示例。
在下文中一共展示了Conn.RemoteAddr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: proxyConnectionTo
func (handler *handler) proxyConnectionTo(server *websocket.Conn) {
handler.logger.Debugf("Output Proxy: Starting to listen to server %v", server.RemoteAddr().String())
var logMessage []byte
defer server.Close()
count := 0
for {
_, data, err := server.ReadMessage()
if err != nil {
handler.logger.Errorf("Output Proxy: Error reading from the server - %v - %v", err, server.RemoteAddr().String())
handler.Done()
return
}
handler.logger.Debugf("Output Proxy: Got message from server %v bytes", len(logMessage))
count++
err = handler.writeMessage(data)
if err != nil {
handler.logger.Errorf("Output Proxy: Error writing to client websocket - %v", err)
return
}
}
}
示例2: newClient
func newClient(ws *websocket.Conn, h *hub, srv *wsServer) *wsClient {
if ws == nil {
log.Panicln("ws cannot be nil")
}
if srv == nil {
log.Panicln("server cannot be nil")
}
maxID++
return &wsClient{
id: maxID,
ws: ws,
h: h,
srv: srv,
subs: make(map[string]string),
inMsgChan: make(chan *wsMessage),
outMsgChan: make(chan *wsMessage),
doneChan: make(chan bool),
socketID: sha1Sum(fmt.Sprintf("%s-%s-%d", ws.RemoteAddr().String(),
ws.LocalAddr().String(), maxID)),
}
}
示例3: NewWSConnection
// new websocket connection wrapper
func NewWSConnection(wsConn *websocket.Conn) *WSConnection {
return &WSConnection{
id: wsConn.RemoteAddr().String(),
wsConn: wsConn,
writeChan: make(chan WSResponse, WriteChanBufferSize), // buffered. we keep track when its full
quitChan: make(chan struct{}),
}
}
示例4: DefaultOnUnsubscribeFactory
/*
DefaultonUnsubscribeFactory will return functions that just log the unsubscribing uri
*/
func (self *Router) DefaultOnUnsubscribeFactory(ws *websocket.Conn, principal string) func(s *Subscription, reason interface{}) {
return func(s *Subscription, reason interface{}) {
self.Debugf("%v\t%v\t%v\t%v\t[unsubscribing]", ws.RemoteAddr(), principal, s.Name(), reason)
if self.LogLevel > wsubs.TraceLevel {
self.Tracef("%s", debug.Stack())
}
}
}
示例5: newConnection
func newConnection(conn *ws.Conn) *connection {
c := &connection{
conn: conn,
ch: make(chan map[string]*string, 10),
}
c.listener = statemanager.NewListener(fmt.Sprintf("websocket(%v)", conn.RemoteAddr()), c.processUpdates)
return c
}
示例6: NewWebsocketSink
func NewWebsocketSink(appId string, givenLogger *gosteno.Logger, ws *websocket.Conn, keepAliveInterval time.Duration, wsMessageBufferSize uint) Sink {
return &WebsocketSink{
logger: givenLogger,
appId: appId,
ws: ws,
clientAddress: ws.RemoteAddr(),
keepAliveInterval: keepAliveInterval,
wsMessageBufferSize: wsMessageBufferSize,
}
}
示例7: Message
func (c *Chat) Message(msg *Incoming, _ *nothing, ws *websocket.Conn) error {
log.Printf("recv from %v:%#v\n", ws.RemoteAddr(), msg)
c.broadcast.Broadcast <- Outgoing{
Time: time.Now(),
From: msg.From,
Message: msg.Message,
}
return nil
}
示例8: sendMessagesToWebsocket
func sendMessagesToWebsocket(logMessages []*logmessage.Message, ws *websocket.Conn, logger *gosteno.Logger) {
for _, message := range logMessages {
err := ws.WriteMessage(websocket.BinaryMessage, message.GetRawMessage())
if err != nil {
logger.Debugf("Dump Sink %s: Error when trying to send data to sink %s. Requesting close. Err: %v", ws.RemoteAddr(), err)
} else {
logger.Debugf("Dump Sink %s: Successfully sent data", ws.RemoteAddr())
}
}
}
示例9: NewWSConnection
// new websocket connection wrapper
func NewWSConnection(baseConn *websocket.Conn, funcMap map[string]*RPCFunc, evsw events.EventSwitch) *wsConnection {
wsc := &wsConnection{
remoteAddr: baseConn.RemoteAddr().String(),
baseConn: baseConn,
writeChan: make(chan RPCResponse, writeChanCapacity), // error when full.
funcMap: funcMap,
evsw: evsw,
}
wsc.QuitService = *NewQuitService(log, "wsConnection", wsc)
return wsc
}
示例10: NewCcusConn
func NewCcusConn(ws *websocket.Conn, cc_in chan updateInfo) *ccusConn {
log.Printf("ws[%s]:new connect %s", ws.RemoteAddr(), ws.LocalAddr())
ws.SetReadDeadline(time.Now().Add(pongWait))
ws.SetWriteDeadline(time.Now().Add(writeWait))
pc := &ccusConn{}
pc.ws = ws
pc.cc_in = cc_in
go pc.receiver()
return pc
}
示例11: newConnection
// Creates a new Connection
func newConnection(ws *websocket.Conn, o *Options) *Connection {
return &Connection{
o,
ws,
ws.RemoteAddr(),
make(chan error, 1),
make(chan int, 1),
make(chan bool, 3),
make(chan error, 1),
make(chan bool, 1),
nil,
}
}
示例12: makeWebsocketListener
func makeWebsocketListener(ws *websocket.Conn, done chan struct{}) deploy.Listener {
return func(logs <-chan deploy.LogEntry) {
defer func() {
done <- struct{}{}
}()
for entry := range logs {
err := ws.WriteJSON(entry)
if err != nil {
log.Printf("error writing to websocket: %s. (remote address=%s)\n", err, ws.RemoteAddr())
return
}
}
}
}
示例13: PubSubHandler
func PubSubHandler(conn *websocket.Conn, pubsubClient *redis.PubSub) {
for {
msgi, err := pubsubClient.ReceiveMessage()
if err != nil {
return
}
switch msg := interface{}(msgi).(type) {
case *redis.Message:
var json_blob interface{}
bytes_blob := []byte(msg.Payload)
if err := json.Unmarshal(bytes_blob, &json_blob); err != nil {
logger.Printf("[%s][error] failed to parse JSON %v, because %v", conn.RemoteAddr(), msg.Payload, err)
continue
}
if err := conn.WriteJSON(json_blob); err != nil {
logger.Printf("[%s][error] failed to send JSON, because %v", conn.RemoteAddr(), err)
conn.Close()
return
}
logger.Printf("[%s][send] OK", conn.RemoteAddr())
default:
logger.Printf("[%s][error] Unkown message: %s", conn.RemoteAddr(), msg)
return
}
}
}
示例14: newPlayer
func newPlayer(ws *websocket.Conn) *player {
self := &player{}
self.ws = ws
// Bot players do not use a websocket.
if self.ws != nil {
self.output = make(chan []byte, 256)
//self.compressor = backstream.NewWriter(self, 0)
self.addr = ws.RemoteAddr()
} else {
self.output = nil
}
// Creating controller.
self.control = NewControl()
self.speedFactor = 1.0
// Creating a ship.
self.Ship = ship.NewShip()
self.Ship.Entity.Kind = (1 + rand.Intn(8))
switch self.Ship.Entity.Kind {
case 1, 2, 3, 4:
self.Ship.Entity.Width = 80
self.Ship.Entity.Height = 120
case 5, 6, 7, 8:
self.Ship.Entity.Width = 80
self.Ship.Entity.Height = 110
}
self.Ship.Entity.Model = fmt.Sprintf("ship-%d", self.Ship.Entity.Kind)
self.hitValue = 2
self.Life = playerMaxLife
self.bulletType = BULLET_1X
self.shootTicks = 0
// Default values.
self.SetSpeed(0)
self.SetDirection(0, -1)
self.SetPosition(0, 0)
return self
}
示例15: sendMessagesToWebsocket
func sendMessagesToWebsocket(envelopes []*events.Envelope, websocketConnection *gorilla.Conn, logger *gosteno.Logger) {
for _, messageEnvelope := range envelopes {
envelopeBytes, err := proto.Marshal(messageEnvelope)
if err != nil {
logger.Errorf("Websocket Server %s: Error marshalling %s envelope from origin %s: %s", websocketConnection.RemoteAddr(), messageEnvelope.GetEventType().String(), messageEnvelope.GetOrigin(), err.Error())
continue
}
err = websocketConnection.WriteMessage(gorilla.BinaryMessage, envelopeBytes)
if err != nil {
logger.Errorf("Websocket Server %s: Error when trying to send data to sink %s. Err: %v", websocketConnection.RemoteAddr(), err)
} else {
logger.Debugf("Websocket Server %s: Successfully sent data", websocketConnection.RemoteAddr())
}
}
}