-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imported first server and client code
drafted new protocol
- Loading branch information
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |