4 changed files with 138 additions and 1 deletions
@ -0,0 +1,40 @@ |
|||||
|
package util |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"fssc/config" |
||||
|
|
||||
|
"net" |
||||
|
) |
||||
|
|
||||
|
// udp 模式发送文件
|
||||
|
/* |
||||
|
* sip string 目标服务器 |
||||
|
* furl string 文件的路径 |
||||
|
*/ |
||||
|
func UpdSend(sip string, furl string) { |
||||
|
// 1、获取udp addr
|
||||
|
remoteAddr, err := net.ResolveUDPAddr("udp", sip+":9099") |
||||
|
if err != nil { |
||||
|
fmt.Printf("Failed to resolve %s: %v\n", sip, err) |
||||
|
return |
||||
|
} |
||||
|
// 2、 监听端口
|
||||
|
conn, err := net.DialUDP("udp", nil, remoteAddr) |
||||
|
if err != nil { |
||||
|
fmt.Printf("Failed to dial %s: %v\n", sip, err) |
||||
|
return |
||||
|
} |
||||
|
defer conn.Close() |
||||
|
// 3、在端口发送数据
|
||||
|
message := fmt.Sprintf("%s%s%s", config.G.DeviceName, "|", "sender") |
||||
|
// 向链接通道发送数据 数据包头
|
||||
|
conn.Write([]byte(message)) |
||||
|
// 发送文件
|
||||
|
// go func() {
|
||||
|
// err := transfer.SendFiles(furl, fmt.Sprintf("http://%s", remoteAddr))
|
||||
|
// if err != nil {
|
||||
|
// fmt.Printf("Send file to %s error: %s\n", remoteAddr, err)
|
||||
|
// }
|
||||
|
// }()
|
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<title>send file to server</title> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
|
<link rel="stylesheet" href="/static/static/css/bootstrap.css"> |
||||
|
<script type="text/javascript" src="/static/static/js/jquery.min.js"></script> |
||||
|
<script type="text/javascript" src="/static/static/js/bootstrap.min.js"></script> |
||||
|
</head> |
||||
|
<body> |
||||
|
|
||||
|
<div class="jumbotron"><div> |
||||
|
|
||||
|
<div class="container"> |
||||
|
|
||||
|
<form method="post" action="/upfile"> |
||||
|
<div class="form-group"> |
||||
|
|
||||
|
<div class="input-group"> |
||||
|
<input type="hidden" class="form-control" name="bpath" value="{{.Bpath}}" readonly /> |
||||
|
</div> |
||||
|
|
||||
|
<div class="input-group"> |
||||
|
<input type="hidden" class="form-control" name="bfile" value="{{.Bfile}}" readonly /> |
||||
|
</div> |
||||
|
|
||||
|
<div class="input-group"> |
||||
|
<div class="input-group-addon">服务器ip</div> |
||||
|
<input type="text" class="form-control" id="exampleInputAmount" name="sip" placeholder="eg:192.168.66.99"> |
||||
|
|
||||
|
</div> |
||||
|
</div> |
||||
|
<button type="submit" class="btn btn-primary">Transfer</button> |
||||
|
</form> |
||||
|
</div> |
||||
|
|
||||
|
|
||||
|
|
||||
|
</body> |
||||
|
</html> |
||||
Loading…
Reference in new issue