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

telnet login no response #1

Open
yufengjinsong opened this issue May 11, 2020 · 0 comments
Open

telnet login no response #1

yufengjinsong opened this issue May 11, 2020 · 0 comments

Comments

@yufengjinsong
Copy link

yufengjinsong commented May 11, 2020

	out := bytes.NewBuffer(nil)
	var buffer bytes.Buffer
	var p []byte
	var crlfBuffer [2]byte = [2]byte{'\r','\n'}
	crlf := crlfBuffer[:]
	time.Sleep(1 * time.Second)
	var readBuffer [2]byte
	readP := readBuffer[1:]
	for {
		fmt.Println("telnet_cmd.go 111111111111")
		n, err := c.dataReader.Read(readP)
		fmt.Println("telnet_cmd.go  22222222222222")
		if n <= 0 && nil == err {
			continue
		} else if n <= 0 && nil != err {
			break
		}
		LongWrite(out, readP)
		if (readBuffer[0] == '#' || readBuffer[0] == ':') && readBuffer[1] == ' ' {
			break
		}
		readBuffer[0] = readBuffer[1]
	}

	for _, cmd := range []string{user, pwd} {
		buffer.Write([]byte(cmd))
		buffer.Write(crlf)

		p = buffer.Bytes()

		n, err := LongWrite(c.dataWriter, p)
		if nil != err {
			break
		}
		if expected, actual := int64(len(p)), n; expected != actual {
			fmt.Printf("Transmission problem: tried sending %d bytes, but actually only sent %d bytes. \n ", expected, actual)
			return fmt.Errorf("Transmission problem: tried sending %d bytes, but actually only sent %d bytes. \n ", expected, actual)
		}

		buffer.Reset()

		for {
			n, err := c.dataReader.Read(readP)
			if n <= 0 && nil == err {
				continue
			} else if n <= 0 && nil != err {
				break
			}
			LongWrite(out, readP)
			if (readBuffer[0] == '#' || readBuffer[0] == ':') && readBuffer[1] == ' ' {
				break
			}
			readBuffer[0] = readBuffer[1]
		}

	}

	time.Sleep(3 * time.Millisecond)
	return nil
}```
when i login  it will block in
`
fmt.Println("telnet_cmd.go 111111111111")
n, err := c.dataReader.Read(readP)
fmt.Println("telnet_cmd.go  22222222222222")
`
my develop environment is  win10  
Anyone konw why?
thanks 
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

1 participant