Пример #1
0
func wd(z int) uint {
	//
	if z < 0 {
		z = -z
	}
	return 1 + nat.Wd(uint(z))
}
Пример #2
0
func New(n uint) *Imp {
	//
	x := new(Imp)
	x.start = n
	x.wd = nat.Wd(n)
	x.zero = n%10 == 0
	if x.wd > 9 {
		x.wd = 9
	}
	switch {
	case x.wd <= 2:
		x.invalid = 1e2
	case x.wd <= 4:
		x.invalid = 1e4
	default:
		x.invalid = 1e9
	}
	x.n = x.invalid
	x.cF, x.cB = col.ScreenF, col.ScreenB
	return x
}
Пример #3
0
func (x *Imp) Go() {
	//
	if x.gone {
		return
	}
	x.gone = true
	portstring := nat.StringFmt(uint(x.port), nat.Wd(uint(x.port)), true)
	if x.isServer {
		if x.info {
			println("nchan.Go started on server", x.server)
		}
		x.addr, _ = net.ResolveTCPAddr(tcp, ":"+portstring)
		//    if x.err != nil { Stop (pack, 2) }
		x.list, _ = net.ListenTCP(tcp, x.addr)
		//    if x.err != nil { Stop (pack, 3) }
		if x.oneOne {
			var e error
			x.conn, e = x.list.Accept() // x.conn.RemoteAddr().(*net.TCPAddr).IP == ipFar
			if e != nil || x.conn == nil {
				Stop(pack, 4)
			}
		} else {
			if x.info {
				println("server", x.server, "is up")
			}
			x.in, x.out = make(chan Any), make(chan Any)
			go func() {
				for {
					conn, err := x.list.Accept()
					if err == nil {
						x.nClients++
						go x.serve(conn)
					} else {
						// if tst { println ("not accepted because " + err.String()) }
					}
				}
			}()
		}
	} else { // client
		if tst {
			println("nchan.Go started for", x.server, "as client")
		}
		x.farHost.SetFormat(host.Hostname)
		dialaddr := x.farHost.String() + ":" + portstring
		for {
			//      println ("waiting for server", x.server)
			x.conn, x.err = net.Dial(tcp, dialaddr)
			if x.err == nil {
				break
			}
			time.Sleep(2e9)
		}
		if x.conn == nil {
			Stop(pack, 5)
		}
		if tst {
			println("nchan.Go.Dial", x.server, "war erfolgreich")
		}
		//    if x.info { errh.DelHint () }
	}
}