Beispiel #1
0
func Httpserver() {
	addr := config.String("http_addr")
	log.Printf(">>>>>>>websocket端口:%s<<<<<<<<<<", addr)
	http.HandleFunc("/chat", handler)
	http.Handle("/", websocket.Handler(connHandler))
	err := http.ListenAndServe(":"+addr, nil)
	if err != nil {
		fmt.Println("httpserver:", err)
		config.Logger.Error("http server:", err)
	}

	// log.Println(">>>>>>>>websocket服务器启动<<<<<<<<")
	// log.Println(">>>>>>>>等待客户端连接<<<<<<<<<")
}
Beispiel #2
0
package main

//服务器端
import (
	"aTalk/server/common"
	"aTalk/server/config"
	"aTalk/server/controller"
	"runtime"
)

var PORT = config.String("port")

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	common.InitDB()
	controller.Start(":" + PORT)

}
Beispiel #3
0
/*
初始化mongodb数据库,同时初始化日志文件
*/

package common

import (
	"aTalk/server/config"
	"github.com/astaxie/beego/logs"
	"gopkg.in/mgo.v2"
)

//声明
var (
	URL     = config.String("db_host")
	db_name = config.String("db_name")
	DBMongo *mgo.Database
	Logger  *logs.BeeLogger
)

//配置日志文件
func initLog() {
	Logger = logs.NewLogger(10000)
	Logger.EnableFuncCallDepth(true)
	Logger.SetLogger("file", `{"filename":"diary/diary.log"}`)
}

//初始化数据库,并添加索引
func InitDB() {
	initLog()
	session, err := mgo.Dial(URL) //连接数据库
Beispiel #4
0
/*
初始化mongodb数据库,同时初始化日志文件
*/

package common

import (
	"aTalk/server/config"
	"github.com/astaxie/beego/logs"
	"gopkg.in/mgo.v2"
)

//声明
var (
	URL = config.String("db_host")
)
Beispiel #5
0
package main

import (
	"aTalk/protocol"
	"aTalk/server/common"
	"aTalk/server/config"
	"fmt"
	"github.com/golang/protobuf/proto"
	"io"
	"net"
	"os"
)

var (
	file_host = config.String("file_host")
)

func main() {
	listener, err := net.Listen("tcp", file_host)
	if err != nil {
		common.Logger.Error("listen:", err)
		os.Exit(-1)
	}
	defer listener.Close()

	for {
		conn, err := listener.Accept()
		if err != nil {
			common.Logger.Warn("accept:", err)
			continue
		}