Skip to content

Commit

Permalink
imported first server and client code
Browse files Browse the repository at this point in the history
drafted new protocol
  • Loading branch information
lechner committed Apr 26, 2017
1 parent 5275ffb commit 1c5a3e7
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
37 changes: 37 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"io"
"log"
"net"
"time"
)

func reader(r io.Reader) {
buf := make([]byte, 1024)
for {
n, err := r.Read(buf[:])
if err != nil {
return
}
println("Client got:", string(buf[0:n]))
}
}

func main() {
c, err := net.Dial("unix", "/tmp/echo.sock")
if err != nil {
panic(err)
}
defer c.Close()

go reader(c)
for {
_, err := c.Write([]byte("hi"))
if err != nil {
log.Fatal("write error:", err)
break
}
time.Sleep(1e9)
}
}
44 changes: 44 additions & 0 deletions flexipam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import {
"encoding/xml"
"fmt"
}

type Operations struct {
operator string
}


type Protocol struct {

Name string `xml:"name"`
Addresses []struct {
Street string `xml:"street"`
City string `xml:"city"`
Type string `xml:"type,attr"`
} `xml:"addresses>address"`
}



func main() {

fmt.Println("FLEXIPAM")

baseDir = "sample-config/"
protocolDir = baseDir + "protocols/"
protocolName = "login.protocol"
protocolPath = protocolDir + "login.protocol"

protocolFile, err := os.Open(protocolPath)
if err != nil {
fmt.Println("Error opening file", protocolPath, ":", err)
return
}
defer protocolFile.Close()

var protocol Protocol
xml.Unmarshal(protocolFile, &protocol)

}
48 changes: 48 additions & 0 deletions sample-config/protocols/login.new.protocol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<protocol>

<stage>
<name>contact</name>
<all>
<include>common-contact.module</include>
</all>
</stage>

<stage>
<name>engage</name>
<undo>final</undo>
<all>
<include>common-engage.module</include>
</all>
</stage>

<stage>
<name>recognize</name>
<any>
<include>common-recognize.module</include>
</any>
</stage>

<stage>
<name>admit"</name>
<all>
<include>common-admit.module</include>
</all>
</stage>

<stage>
<name>seat</name>
<all>
<include>common-seat.module</include>
</all>
</stage>

<stage>
<name>invoice</name>
<undo>now</undo>
<all>
<include>common-invoice.module</include>
</all>
</stage>

</protocol>
39 changes: 39 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"log"
"net"
)

func echoServer(c net.Conn) {
for {
buf := make([]byte, 512)
nr, err := c.Read(buf)
if err != nil {
return
}

data := buf[0:nr]
println("Server got:", string(data))
_, err = c.Write(data)
if err != nil {
log.Fatal("Write: ", err)
}
}
}

func main() {
l, err := net.Listen("unix", "/tmp/echo.sock")
if err != nil {
log.Fatal("listen error:", err)
}

for {
fd, err := l.Accept()
if err != nil {
log.Fatal("accept error:", err)
}

go echoServer(fd)
}
}

0 comments on commit 1c5a3e7

Please sign in to comment.