[GH-ISSUE #2516] Make a Go Desktop Application FRP Client #1997

Closed
opened 2026-05-05 13:17:28 -06:00 by gitea-mirror · 7 comments
Owner

Originally created by @hinupurthakur on GitHub (Aug 6, 2021).
Original GitHub issue: https://github.com/fatedier/frp/issues/2516

The solution you want

Instead of using the CLI to start a FRP Client, I want to use this repository as a package, On exploring I found out https://github.com/fatedier/frp/blob/dev/client/service.go but how to create a client with the following .ini:

[common]
server_addr = {{ .Envs.FRP_SERVER_ADDR }}
server_port = {{ .Envs.FRP_SERVER_PORT }}

[wev]
type = {{ .Envs.FRP_WEB_TYPE }}
local_port = {{ .Envs.FRP_WEB_LOCAL_PORT }}
custom_domains = {{ .Envs.FRP_WEB_CUSTOM_DOMAINS }}

Alternatives considered

How to implement this function

Application scenarios of this function

I implemented something like this:

func StartClient() {
	cfg, err := ini.Load("./src/frpc/frpc.ini")
	if err != nil {
		fmt.Printf("Fail to read file: %v", err)
		os.Exit(1)
	}

	clientcfg := config.GetDefaultClientConf()
	clientcfg.ServerAddr = cfg.Section("common").Key("server_addr").String()
	clientcfg.ServerPort = cfg.Section("common").Key("server_port").MustInt()
	
	svr, err := client.NewService(clientcfg, nil, nil, "./src/frpc/frpc.ini")
	if err != nil {
		log.Errorln(err)
	}
	err = svr.Run()
	if err != nil {
		return
	}
}

BUt I am not able to understand what should be the values of VisitorCfg and ProxyCfg. And How to use the [web] section of the .ini file as we can use in CLI

From the above code I am getting the following logs:

2021/08/06 12:40:25 [I] [service.go:304] [f232664391e39fef] login to server success, get run id [f232664391e39fef], server udp port [0]
2021/08/06 12:40:25 [W] [control.go:261] [f232664391e39fef] read error: message type error
2021/08/06 12:40:25 [I] [control.go:282] [f232664391e39fef] control writer is closing
2021/08/06 12:40:25 [I] [visitor_manager.go:60] [f232664391e39fef] gracefully shutdown visitor manager
2021/08/06 12:40:25 [I] [service.go:177] [f232664391e39fef] try to reconnect to server...
2021/08/06 12:40:26 [I] [service.go:304] [f232664391e39fef] login to server success, get run id [f232664391e39fef], server udp port [0]
Originally created by @hinupurthakur on GitHub (Aug 6, 2021). Original GitHub issue: https://github.com/fatedier/frp/issues/2516 <!-- From Chinese to English by machine translation, welcome to revise and polish. --> **The solution you want** <!--A clear and concise description of the solution you want. --> Instead of using the CLI to start a FRP Client, I want to use this repository as a package, On exploring I found out https://github.com/fatedier/frp/blob/dev/client/service.go but how to create a client with the following .ini: ``` [common] server_addr = {{ .Envs.FRP_SERVER_ADDR }} server_port = {{ .Envs.FRP_SERVER_PORT }} [wev] type = {{ .Envs.FRP_WEB_TYPE }} local_port = {{ .Envs.FRP_WEB_LOCAL_PORT }} custom_domains = {{ .Envs.FRP_WEB_CUSTOM_DOMAINS }} ``` **Alternatives considered** <!--A clear and concise description of any alternative solutions or features you have considered. --> **How to implement this function** <!--Implementation steps for the solution you want. --> **Application scenarios of this function** <!--Make a clear and concise description of the application scenario of the solution you want. --> I implemented something like this: ``` func StartClient() { cfg, err := ini.Load("./src/frpc/frpc.ini") if err != nil { fmt.Printf("Fail to read file: %v", err) os.Exit(1) } clientcfg := config.GetDefaultClientConf() clientcfg.ServerAddr = cfg.Section("common").Key("server_addr").String() clientcfg.ServerPort = cfg.Section("common").Key("server_port").MustInt() svr, err := client.NewService(clientcfg, nil, nil, "./src/frpc/frpc.ini") if err != nil { log.Errorln(err) } err = svr.Run() if err != nil { return } } ``` BUt I am not able to understand what should be the values of VisitorCfg and ProxyCfg. And How to use the `[web]` section of the .ini file as we can use in CLI From the above code I am getting the following logs: ``` 2021/08/06 12:40:25 [I] [service.go:304] [f232664391e39fef] login to server success, get run id [f232664391e39fef], server udp port [0] 2021/08/06 12:40:25 [W] [control.go:261] [f232664391e39fef] read error: message type error 2021/08/06 12:40:25 [I] [control.go:282] [f232664391e39fef] control writer is closing 2021/08/06 12:40:25 [I] [visitor_manager.go:60] [f232664391e39fef] gracefully shutdown visitor manager 2021/08/06 12:40:25 [I] [service.go:177] [f232664391e39fef] try to reconnect to server... 2021/08/06 12:40:26 [I] [service.go:304] [f232664391e39fef] login to server success, get run id [f232664391e39fef], server udp port [0] ```
gitea-mirror 2026-05-05 13:17:28 -06:00
Author
Owner

@fatedier commented on GitHub (Aug 6, 2021):

ProxyCfg and VisitorCfg is parsed from ini file. You can find code here https://github.com/fatedier/frp/blob/dev/pkg/config/client.go

It's not designed as package to use now. Maybe it's difficult for you.

But i plan to refactor codes to make things easy.

<!-- gh-comment-id:894062466 --> @fatedier commented on GitHub (Aug 6, 2021): ProxyCfg and VisitorCfg is parsed from ini file. You can find code here https://github.com/fatedier/frp/blob/dev/pkg/config/client.go It's not designed as package to use now. Maybe it's difficult for you. But i plan to refactor codes to make things easy.
Author
Owner

@hinupurthakur commented on GitHub (Aug 6, 2021):

@fatedier I checked that too, but I am not able to understand what should be the value to be passed for ProxyCfg and VisitorCfg to the function client.NewService() so that I can use the .ini file provided above and start a frp client.

<!-- gh-comment-id:894064027 --> @hinupurthakur commented on GitHub (Aug 6, 2021): @fatedier I checked that too, but I am not able to understand what should be the value to be passed for ProxyCfg and VisitorCfg to the function client.NewService() so that I can use the .ini file provided above and start a frp client.
Author
Owner

@fatedier commented on GitHub (Aug 6, 2021):

You should read more codes by yourself. Maybe https://github.com/fatedier/frp/blob/dev/cmd/frpc/sub/root.go#L168

<!-- gh-comment-id:894067293 --> @fatedier commented on GitHub (Aug 6, 2021): You should read more codes by yourself. Maybe https://github.com/fatedier/frp/blob/dev/cmd/frpc/sub/root.go#L168
Author
Owner

@hinupurthakur commented on GitHub (Aug 6, 2021):

@fatedier Thanks for the help! but I am still getting such logs. Should I also make the control.go code local to my project?

2021/08/06 15:10:00 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0]
2021/08/06 15:10:00 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web]
2021/08/06 15:10:00 [W] [control.go:261] [6894c0ccad350077] read error: message type error
2021/08/06 15:10:00 [I] [control.go:282] [6894c0ccad350077] control writer is closing
2021/08/06 15:10:00 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager
2021/08/06 15:10:00 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server...
2021/08/06 15:10:00 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0]
2021/08/06 15:10:00 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web]
2021/08/06 15:10:00 [W] [control.go:261] [6894c0ccad350077] read error: message type error
2021/08/06 15:10:00 [W] [control.go:287] [6894c0ccad350077] write message to control connection error: stream closed
2021/08/06 15:10:00 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server...
2021/08/06 15:10:00 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager
2021/08/06 15:10:01 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0]
2021/08/06 15:10:01 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web]
2021/08/06 15:10:01 [W] [control.go:261] [6894c0ccad350077] read error: message type error
2021/08/06 15:10:01 [W] [control.go:287] [6894c0ccad350077] write message to control connection error: stream closed
2021/08/06 15:10:01 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager
2021/08/06 15:10:01 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server...
2021/08/06 15:10:01 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0]
2021/08/06 15:10:01 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web]
2021/08/06 15:10:01 [W] [control.go:261] [6894c0ccad350077] read error: message type error
2021/08/06 15:10:01 [I] [control.go:282] [6894c0ccad350077] control writer is closing
2021/08/06 15:10:01 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager
2021/08/06 15:10:02 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server...
2021/08/06 15:10:03 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0]
2021/08/06 15:10:03 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web]
2021/08/06 15:10:03 [W] [control.go:261] [6894c0ccad350077] read error: message type error
2021/08/06 15:10:03 [I] [control.go:282] [6894c0ccad350077] control writer is closing
2021/08/06 15:10:03 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager
2021/08/06 15:10:05 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server...
2021/08/06 15:10:05 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0]
<!-- gh-comment-id:894140974 --> @hinupurthakur commented on GitHub (Aug 6, 2021): @fatedier Thanks for the help! but I am still getting such logs. Should I also make the `control.go` code local to my project? ``` 2021/08/06 15:10:00 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0] 2021/08/06 15:10:00 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web] 2021/08/06 15:10:00 [W] [control.go:261] [6894c0ccad350077] read error: message type error 2021/08/06 15:10:00 [I] [control.go:282] [6894c0ccad350077] control writer is closing 2021/08/06 15:10:00 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager 2021/08/06 15:10:00 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server... 2021/08/06 15:10:00 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0] 2021/08/06 15:10:00 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web] 2021/08/06 15:10:00 [W] [control.go:261] [6894c0ccad350077] read error: message type error 2021/08/06 15:10:00 [W] [control.go:287] [6894c0ccad350077] write message to control connection error: stream closed 2021/08/06 15:10:00 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server... 2021/08/06 15:10:00 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager 2021/08/06 15:10:01 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0] 2021/08/06 15:10:01 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web] 2021/08/06 15:10:01 [W] [control.go:261] [6894c0ccad350077] read error: message type error 2021/08/06 15:10:01 [W] [control.go:287] [6894c0ccad350077] write message to control connection error: stream closed 2021/08/06 15:10:01 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager 2021/08/06 15:10:01 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server... 2021/08/06 15:10:01 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0] 2021/08/06 15:10:01 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web] 2021/08/06 15:10:01 [W] [control.go:261] [6894c0ccad350077] read error: message type error 2021/08/06 15:10:01 [I] [control.go:282] [6894c0ccad350077] control writer is closing 2021/08/06 15:10:01 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager 2021/08/06 15:10:02 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server... 2021/08/06 15:10:03 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0] 2021/08/06 15:10:03 [I] [proxy_manager.go:144] [6894c0ccad350077] proxy added: [web] 2021/08/06 15:10:03 [W] [control.go:261] [6894c0ccad350077] read error: message type error 2021/08/06 15:10:03 [I] [control.go:282] [6894c0ccad350077] control writer is closing 2021/08/06 15:10:03 [I] [visitor_manager.go:60] [6894c0ccad350077] gracefully shutdown visitor manager 2021/08/06 15:10:05 [I] [service.go:177] [6894c0ccad350077] try to reconnect to server... 2021/08/06 15:10:05 [I] [service.go:304] [6894c0ccad350077] login to server success, get run id [6894c0ccad350077], server udp port [0] ```
Author
Owner

@hinupurthakur commented on GitHub (Aug 6, 2021):

@fatedier Or is there any other way to use frp without installing it manually on the Client side?

<!-- gh-comment-id:894226812 --> @hinupurthakur commented on GitHub (Aug 6, 2021): @fatedier Or is there any other way to use frp without installing it manually on the Client side?
Author
Owner

@hinupurthakur commented on GitHub (Aug 9, 2021):

@fatedier Update on this task There are new logs:

2021/08/09 17:52:06 [W] [control.go:261] [5d59546259a70e7a] read error: message length exceed the limit
2021/08/09 17:52:06 [W] [control.go:287] [5d59546259a70e7a] write message to control connection error: stream closed```
<!-- gh-comment-id:895178983 --> @hinupurthakur commented on GitHub (Aug 9, 2021): @fatedier Update on this task There are new logs: ``` 2021/08/09 17:52:06 [W] [control.go:261] [5d59546259a70e7a] read error: message length exceed the limit 2021/08/09 17:52:06 [W] [control.go:287] [5d59546259a70e7a] write message to control connection error: stream closed```
Author
Owner

@github-actions[bot] commented on GitHub (Sep 9, 2021):

Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.

<!-- gh-comment-id:915665553 --> @github-actions[bot] commented on GitHub (Sep 9, 2021): Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.
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#1997
No description provided.