Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something wrong with address conversion #32

Open
ont opened this issue Oct 28, 2017 · 4 comments
Open

Something wrong with address conversion #32

ont opened this issue Oct 28, 2017 · 4 comments

Comments

@ont
Copy link

ont commented Oct 28, 2017

Hello, I am trying to write simple client and server but got strange error with wrong server address name.
Here is code for server:

package main

import (
	"fmt"
	"github.com/zenhotels/astranet"
	"io/ioutil"
	"net"
)

func main() {
	mtx := astranet.New().Server() // create astranet multiplexer

	listener, err := mtx.Bind("", "echo_server")
	if err != nil {
		panic(err)
	}

	mtx.ListenAndServe("tcp4", ":10000")

	for {
		conn, err := listener.Accept()
		if err != nil {
			fmt.Println("Error:", err)
			continue
		}
		go handle(conn)
	}
}

func handle(conn net.Conn) {
	bytes, err := ioutil.ReadAll(conn)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Println(string(bytes))
}

... and here is code for client:

package main

import (
	"github.com/zenhotels/astranet"
	"github.com/zenhotels/astranet/addr"
)

func main() {
	mtx := astranet.New().Client() // create astranet multiplexer
	mtx.Join("tcp4", "0.0.0.0:10000")

	res, err := addr.Host2Uint("echo_server")
	if err != nil {
		panic(err)
	}
	println("addr conversion -->", res, addr.Uint2Host(res))

	conn, err := mtx.Dial("", "echo_server")
	if err != nil {
		panic(err)
	}

	conn.Write([]byte("test string"))
}

Server starts without errors, but for client I got this output:

addr conversion --> 8775379317412314602 echo_serveo
panic: address echo_serveo: No route to

goroutine 1 [running]:
main.main()
	/home/ont/proj/use/nomnom/tests/src/client/main.go:20 +0x2c5

Pay attention to the error in echo_serveo (wrong last letter o instead of r).
Do I use the name of the service correctly for the mtx.Bind and mtx.Dial?

@xlab
Copy link
Contributor

xlab commented Oct 29, 2017

@ont seems that the length is limited, try to use a shorter one. If you need to add namespaces for the services, use Env()

@ont
Copy link
Author

ont commented Oct 29, 2017

But seems that Bind doesn't have any limitations for service name length:
https://github.com/zenhotels/astranet/blob/master/cli/local2astra/main.go#L110

...
var appName = flag.String("name", uuid.NewV4().String(), "name of application to publish")
...
var fwdService, fwdErr = astraNet.Bind("", *appName)

As I can see this cli program expose local non-astranet service to astranet network as uuid4-named service.
And is it supposed to be accessed via Dial call?

@biinilya
Copy link
Contributor

biinilya commented Nov 1, 2017

@ont thanks for the issue. Let me check and I will be back.

@xlab
Copy link
Contributor

xlab commented Nov 26, 2018

@biinilya ping, wake up!

#33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants