Created
April 24, 2013 21:51
-
-
Save gmile/5455885 to your computer and use it in GitHub Desktop.
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
package main | |
import "net" | |
import "bufio" | |
func main() { | |
conn, err := net.Dial("tcp", ":8080") | |
if err != nil { | |
println("There was an error:", err) | |
} | |
my_string_writer := bufio.NewWriter(conn) | |
_, err = my_string_writer.WriteString("api_call_1") | |
err = my_string_writer.Flush() | |
_, err = my_string_writer.WriteString("api_call_2") | |
err = my_string_writer.Flush() | |
} |
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
package main | |
import "net" | |
import "bufio" | |
func main() { | |
ln, err := net.Listen("tcp", ":8080") | |
if err != nil { | |
println("There was an error:", err) | |
} | |
for { | |
conn, err := ln.Accept() | |
if err != nil { | |
println("Didn't work") | |
} | |
reader := bufio.NewReader(conn) | |
my_string, err := reader.ReadString('\n') | |
switch my_string { | |
case "api_call_1": println("Hello") | |
case "api_call_2": println("World") | |
default: | |
println(my_string) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment