async www read write

This commit is contained in:
gauthiier
2019-01-04 09:59:01 +01:00
parent 4e0ba79dd9
commit 6bb83ddbcb
6 changed files with 186 additions and 54 deletions
+11 -11
View File
@@ -34,7 +34,7 @@ func Connect() (net.Conn, error){
// ips, err := net.LookupIP("www.google.ca")
var sock net.Conn
host := config.Xcfg.Server.ADDR + ":" + strconv.Itoa(config.Xcfg.Server.PORT)
host := config.Xcfg.IceServer.ADDR + ":" + strconv.Itoa(config.Xcfg.IceServer.PORT)
sock, err := net.Dial("tcp", host)
if err != nil {
@@ -48,14 +48,14 @@ func Connect() (net.Conn, error){
// icecast only for now
// try PUT method
mount := config.Xcfg.Server.MOUNT
mount := config.Xcfg.IceServer.MOUNT
s := spf("PUT %s HTTP/1.1\r\n", mount)
if mount[0] != '/' {
s = spf("PUT /%s HTTP/1.1\r\n", mount)
}
err = socket.Send(sock, []byte(s))
s = spf("%s:%s", config.Xcfg.Server.USR, config.Xcfg.Server.PWD)
s = spf("%s:%s", config.Xcfg.IceServer.USR, config.Xcfg.IceServer.PWD)
sb64 := "Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte(s)) + "\r\n"
err = socket.Send(sock, []byte(sb64))
@@ -65,19 +65,19 @@ func Connect() (net.Conn, error){
s = "Content-Type: audio/mp3\r\n"
err = socket.Send(sock, []byte(s))
s = spf("ice-name: %s\r\n", config.Xcfg.Ice.NAME)
s = spf("ice-name: %s\r\n", config.Xcfg.IceStream.NAME)
err = socket.Send(sock, []byte(s))
s = spf("ice-public: %s\r\n", config.Xcfg.Ice.PUB)
s = spf("ice-public: %s\r\n", config.Xcfg.IceStream.PUB)
err = socket.Send(sock, []byte(s))
s = spf("ice-url: %s\r\n", config.Xcfg.Ice.URL)
s = spf("ice-url: %s\r\n", config.Xcfg.IceStream.URL)
err = socket.Send(sock, []byte(s))
s = spf("ice-genre: %s\r\n", config.Xcfg.Ice.GENRE)
s = spf("ice-genre: %s\r\n", config.Xcfg.IceStream.GENRE)
err = socket.Send(sock, []byte(s))
s = spf("ice-description: %s\r\n", config.Xcfg.Ice.DESC)
s = spf("ice-description: %s\r\n", config.Xcfg.IceStream.DESC)
err = socket.Send(sock, []byte(s))
s = "ice-audio-info: ice-bitrate=192000; ice-channels=2; ice-samplerate=44100\r\n"
@@ -132,14 +132,14 @@ func Send(buff []byte) error {
func Update() error {
host := config.Xcfg.Server.ADDR + ":" + strconv.Itoa(config.Xcfg.Server.PORT)
host := config.Xcfg.IceServer.ADDR + ":" + strconv.Itoa(config.Xcfg.IceServer.PORT)
track := url.QueryEscape(config.Xcfg.Track.NAME)
mount := config.Xcfg.Server.MOUNT
mount := config.Xcfg.IceServer.MOUNT
if mount[0] != '/' {
mount = "/" + mount
}
s := spf("%s:%s", config.Xcfg.Server.USR, config.Xcfg.Server.PWD)
s := spf("%s:%s", config.Xcfg.IceServer.USR, config.Xcfg.IceServer.PWD)
sb64 := "Basic " + base64.StdEncoding.EncodeToString([]byte(s))
header := "GET /admin/metadata?mode=updinfo&mount=" + mount + "&song=" + track + " HTTP/1.0\r\n" +