Created
December 16, 2013 01:57
-
-
Save kellabyte/7981303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/alecthomas/gozmq" | |
| "fmt" | |
| ) | |
| type ClientAgent interface { | |
| ListenAndServe() | |
| Close() | |
| } | |
| type clientAgent struct { | |
| zmqContext *gozmq.Context | |
| clientSocket *gozmq.Socket | |
| } | |
| func NewClientAgent() ClientAgent { | |
| self := &clientAgent{} | |
| self.zmqContext, _ = gozmq.NewContext() | |
| return self | |
| } | |
| func (self *clientAgent) ListenAndServe() { | |
| self.clientSocket, _ = self.zmqContext.NewSocket(gozmq.ROUTER) | |
| self.clientSocket.Bind("tcp://*:5555") | |
| items := gozmq.PollItems{ | |
| gozmq.PollItem{Socket: self.clientSocket, Events: gozmq.POLLIN}, | |
| } | |
| for { | |
| _, err := gozmq.Poll(items, -1) | |
| if err != nil { | |
| break | |
| } | |
| if items[0].REvents & gozmq.POLLIN != 0 { | |
| multiBytes, _ := self.clientSocket.RecvMultipart(0) | |
| fmt.Printf("[SERVER] %v %s\n", multiBytes[0], multiBytes[1]) | |
| } | |
| } | |
| } | |
| func (self *clientAgent) Close() { | |
| self.zmqContext.Close() | |
| self.clientSocket.Close() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| When I try to run this Go application from the plugin I get the error: | |
| /git/go/src/github.com/kellabyte/zmq_test/main.go:6: undefined: NewClientAgent | |
| /git/go/src/github.com/kellabyte/zmq_test/main.go:9: undefined: NewClient | |
| /git/go/src/github.com/kellabyte/zmq_test/main.go:10: undefined: NewClient | |
| /git/go/src/github.com/kellabyte/zmq_test/main.go:11: undefined: NewClient | |
| But if I compile the project it says it builds fine in the plugin. I ran go build and it reported errors. | |
| I fixed the errors and go build now builds this code properly but the errors above still happe in the plugin. | |
| I would love for the plugin just to use go build so that there's not two confusing build systems! | |
| Included is client_agent.go so that you can see the code that complains above does exist. | |
| */ | |
| package main | |
| import "time" | |
| func main() { | |
| agent := NewClientAgent() // Plugin is trying to autocomplete the variable agent as a type that exists in another package | |
| go agent.ListenAndServe() | |
| client1 := NewClient() | |
| client2 := NewClient() | |
| client3 := NewClient() | |
| client1.Connect() | |
| client2.Connect() | |
| client3.Connect() | |
| time.Sleep(time.Second * 5) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you also please post the output of the
go env? Thanks.