[GH-ISSUE #2712] [Feature Request] FRP Client or Server start via frp package instead of binary #2166

Closed
opened 2026-05-05 13:23:37 -06:00 by gitea-mirror · 9 comments
Owner

Originally created by @hinupurthakur on GitHub (Dec 20, 2021).
Original GitHub issue: https://github.com/fatedier/frp/issues/2712

Describe the feature request

Currently to integrate the functionality of the frp to another package we have to integrate the .exe file. Can we use the frp package directly to integrate it. I have requested this feature before as well for version 0.37.1 ( related issue #2516 )

Describe alternatives you've considered

func runClient(cfgFilePath string) error {
	cfg, pxyCfgs, visitorCfgs, err := config.ParseClientConfig(cfgFilePath)
	if err != nil {
		return err
	}
	return startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
}

func startService(
	cfg config.ClientCommonConf,
	pxyCfgs map[string]config.ProxyConf,
	visitorCfgs map[string]config.VisitorConf,
	cfgFile string,
) (err error) {

	log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel,
		cfg.LogMaxDays, cfg.DisableLogColor)

	if cfg.DNSServer != "" {
		s := cfg.DNSServer
		if !strings.Contains(s, ":") {
			s += ":53"
		}
		// Change default dns server for frpc
		net.DefaultResolver = &net.Resolver{
			PreferGo: true,
			Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
				return net.Dial("udp", s)
			},
		}
	}
	svr, errRet := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile)
	if errRet != nil {
		logrus.Errorln(err)
		return
	}
	err = svr.Run()
	if err != nil {
		logrus.Errorln("unable to start client: ", err)
	}
	return
}

Something like this, this is the code snippet picked from the frp client but it doesn't work it gives the error like:

2021/12/20 15:02:31 [I] [service.go:304] [7d45247c15b4cb72] login to server success, get run id [7d45247c15b4cb72], server udp port [0]
2021/12/20 15:02:31 [I] [proxy_manager.go:144] [7d45247c15b4cb72] proxy added: [web]
2021/12/20 15:02:31 [W] [control.go:261] [7d45247c15b4cb72] read error: message type error
2021/12/20 15:02:31 [I] [control.go:282] [7d45247c15b4cb72] control writer is closing
2021/12/20 15:02:31 [I] [visitor_manager.go:60] [7d45247c15b4cb72] gracefully shutdown visitor manager
2021/12/20 15:02:31 [I] [service.go:177] [7d45247c15b4cb72] try to reconnect to server...
2021/12/20 15:02:31 [I] [service.go:304] [7d45247c15b4cb72] login to server success, get run id [7d45247c15b4cb72], server udp port [0]
2021/12/20 15:02:31 [I] [proxy_manager.go:144] [7d45247c15b4cb72] proxy added: [web]
2021/12/20 15:02:31 [W] [control.go:261] [7d45247c15b4cb72] read error: message type error
2021/12/20 15:02:31 [W] [control.go:287] [7d45247c15b4cb72] write message to control connection error: stream closed
2021/12/20 15:02:31 [I] [visitor_manager.go:60] [7d45247c15b4cb72] gracefully shutdown visitor manager
2021/12/20 15:02:31 [I] [service.go:177] [7d45247c15b4cb72] try to reconnect to server...
2021/12/20 15:02:31 [I] [service.go:304] [7d45247c15b4cb72] login to server success, get run id [7d45247c15b4cb72], server udp port [0]
2021/12/20 15:02:31 [I] [proxy_manager.go:144] [7d45247c15b4cb72] proxy added: [web]

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @hinupurthakur on GitHub (Dec 20, 2021). Original GitHub issue: https://github.com/fatedier/frp/issues/2712 ### Describe the feature request Currently to integrate the functionality of the frp to another package we have to integrate the .exe file. Can we use the frp package directly to integrate it. I have requested this feature before as well for version 0.37.1 ( related issue #2516 ) ### Describe alternatives you've considered ``` func runClient(cfgFilePath string) error { cfg, pxyCfgs, visitorCfgs, err := config.ParseClientConfig(cfgFilePath) if err != nil { return err } return startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath) } func startService( cfg config.ClientCommonConf, pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf, cfgFile string, ) (err error) { log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel, cfg.LogMaxDays, cfg.DisableLogColor) if cfg.DNSServer != "" { s := cfg.DNSServer if !strings.Contains(s, ":") { s += ":53" } // Change default dns server for frpc net.DefaultResolver = &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, address string) (net.Conn, error) { return net.Dial("udp", s) }, } } svr, errRet := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile) if errRet != nil { logrus.Errorln(err) return } err = svr.Run() if err != nil { logrus.Errorln("unable to start client: ", err) } return } ``` Something like this, this is the code snippet picked from the frp client but it doesn't work it gives the error like: ``` 2021/12/20 15:02:31 [I] [service.go:304] [7d45247c15b4cb72] login to server success, get run id [7d45247c15b4cb72], server udp port [0] 2021/12/20 15:02:31 [I] [proxy_manager.go:144] [7d45247c15b4cb72] proxy added: [web] 2021/12/20 15:02:31 [W] [control.go:261] [7d45247c15b4cb72] read error: message type error 2021/12/20 15:02:31 [I] [control.go:282] [7d45247c15b4cb72] control writer is closing 2021/12/20 15:02:31 [I] [visitor_manager.go:60] [7d45247c15b4cb72] gracefully shutdown visitor manager 2021/12/20 15:02:31 [I] [service.go:177] [7d45247c15b4cb72] try to reconnect to server... 2021/12/20 15:02:31 [I] [service.go:304] [7d45247c15b4cb72] login to server success, get run id [7d45247c15b4cb72], server udp port [0] 2021/12/20 15:02:31 [I] [proxy_manager.go:144] [7d45247c15b4cb72] proxy added: [web] 2021/12/20 15:02:31 [W] [control.go:261] [7d45247c15b4cb72] read error: message type error 2021/12/20 15:02:31 [W] [control.go:287] [7d45247c15b4cb72] write message to control connection error: stream closed 2021/12/20 15:02:31 [I] [visitor_manager.go:60] [7d45247c15b4cb72] gracefully shutdown visitor manager 2021/12/20 15:02:31 [I] [service.go:177] [7d45247c15b4cb72] try to reconnect to server... 2021/12/20 15:02:31 [I] [service.go:304] [7d45247c15b4cb72] login to server success, get run id [7d45247c15b4cb72], server udp port [0] 2021/12/20 15:02:31 [I] [proxy_manager.go:144] [7d45247c15b4cb72] proxy added: [web] ``` ### Affected area - [X] Docs - [ ] Installation - [X] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [X] Client Plugin - [X] Server Plugin - [ ] Extensions - [X] Others
Author
Owner

@hinupurthakur commented on GitHub (Dec 20, 2021):

@fatedier Please let me know if I can help with this in any possible way, as I would really like this feature to be there with frp. I will be happy to help and contribute.
Thanks!

<!-- gh-comment-id:997766109 --> @hinupurthakur commented on GitHub (Dec 20, 2021): @fatedier Please let me know if I can help with this in any possible way, as I would really like this feature to be there with frp. I will be happy to help and contribute. Thanks!
Author
Owner

@fatedier commented on GitHub (Dec 20, 2021):

read error: message type error

From this log, i guess your server version is not compatible with your client.

<!-- gh-comment-id:997775460 --> @fatedier commented on GitHub (Dec 20, 2021): `read error: message type error` From this log, i guess your server version is not compatible with your client.
Author
Owner

@fatedier commented on GitHub (Dec 20, 2021):

All message types are defined in github.com/fatedier/frp/pkg/msg/msg.go.

<!-- gh-comment-id:997778607 --> @fatedier commented on GitHub (Dec 20, 2021): All message types are defined in `github.com/fatedier/frp/pkg/msg/msg.go`.
Author
Owner

@hinupurthakur commented on GitHub (Dec 20, 2021):

@fatedier Checked and both server and client have same version as 0.38.0

<!-- gh-comment-id:997810599 --> @hinupurthakur commented on GitHub (Dec 20, 2021): @fatedier Checked and both server and client have same version as 0.38.0
Author
Owner

@hinupurthakur commented on GitHub (Dec 20, 2021):

[common]
server_addr = 
server_port = 7000

[web]
type = http
local_port = 8090
custom_domains = 
use_compression = true

For the reference above is my cfg file. @fatedier
It will be really helpful if you could please guide here

<!-- gh-comment-id:997812988 --> @hinupurthakur commented on GitHub (Dec 20, 2021): ``` [common] server_addr = server_port = 7000 [web] type = http local_port = 8090 custom_domains = use_compression = true ``` For the reference above is my cfg file. @fatedier It will be really helpful if you could please guide here
Author
Owner

@fatedier commented on GitHub (Dec 20, 2021):

It's not releated to your configures. This error means received message type is not registered in github.com/fatedier/frp/pkg/msg/msg.go.

I can't help you without any debugging method or full codes.

<!-- gh-comment-id:997816812 --> @fatedier commented on GitHub (Dec 20, 2021): It's not releated to your configures. This error means received message type is not registered in `github.com/fatedier/frp/pkg/msg/msg.go`. I can't help you without any debugging method or full codes.
Author
Owner

@hinupurthakur commented on GitHub (Dec 20, 2021):

@fatedier Below is the repository with whole code please let me know if this is sufficient
https://github.com/hinupurthakur/frpc

<!-- gh-comment-id:997825838 --> @hinupurthakur commented on GitHub (Dec 20, 2021): @fatedier Below is the repository with whole code please let me know if this is sufficient https://github.com/hinupurthakur/frpc
Author
Owner

@fatedier commented on GitHub (Dec 21, 2021):

@hinupurthakur I found this problem caused by you missing these codes https://github.com/fatedier/frp/blob/dev/cmd/frpc/main.go#L28

<!-- gh-comment-id:998521096 --> @fatedier commented on GitHub (Dec 21, 2021): @hinupurthakur I found this problem caused by you missing these codes https://github.com/fatedier/frp/blob/dev/cmd/frpc/main.go#L28
Author
Owner

@hinupurthakur commented on GitHub (Dec 21, 2021):

Thanks @fatedier It worked. 🎉

<!-- gh-comment-id:998526231 --> @hinupurthakur commented on GitHub (Dec 21, 2021): Thanks @fatedier It worked. 🎉
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#2166
No description provided.