Advertisement
nordlaender

simple server go

May 16th, 2013
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.55 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "net"
  6. )
  7.  
  8. type Client struct {
  9. }
  10.  
  11. func main() {
  12.     fmt.Println("starting server")
  13.     ln, err := net.Listen("tcp", "localhost:5000")
  14.     if err != nil {
  15.         fmt.Println("couldn't listen at the port")
  16.         return
  17.     }
  18.  
  19.     for {
  20.         conn, err := ln.Accept()
  21.         if err != nil {
  22.             fmt.Println("couldn't accept the connection")
  23.             return
  24.         }
  25.         b := make([]byte, 1024)
  26.         n, err := conn.Read(b)
  27.         if err != nil {
  28.             fmt.Println("couldn't read the data")
  29.         }
  30.         fmt.Println(n)
  31.         fmt.Println("received the message", string(b))
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement