postbird

package module
v0.0.0-...-75b5537 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2017 License: MIT Imports: 11 Imported by: 0

README

Build Status

PostBird

Easy communication library for Golang

Usage

Quick Start

Run this command in bash or cmd or etc..

go get github.com/ghatdev/postbird

And, add this line

import "github.com/ghatdev/PostBird"

in your code

How to use
  • Server Mode:

    • Call RegisterFunc() to register functions.
    • Call StartServer() to start the server.
  • Client Mode:

    • Call ConnectToRemote() to connect to server.
    • Call CallRemoteFunc() to call registered functions.
    • call RegisterFunc() to register functions..

Example

  • As Server :
package main

import (
  	"PostBird"
  	"fmt"
)

func main() {
  	postbird.RegisterFunc("test", test)
  	postbird.SetBindAddress("0.0.0.0")
  	postbird.StartServer(0)

}

func test(a string) {
  	fmt.Println(a)
}
  • As Client :
package main

import "PostBird"

func main() {
  	postbird.ConnectToRemote(0)
  	postbird.CallRemoteFunc("test", "Hello World!")
}
  • Result (Server Prompt):
    Hello World!

Documentation

Index

Constants

View Source
const (
	DefaultPort          uint   = 8787
	DefaultBindAddress   string = "127.0.0.1"
	DefaultRemoteAddress string = "127.0.0.1"
	DefaultProtocol      uint   = SocketIO
)

따로 set함수들을 호출하지 않으면 밑의 값들을 이용한다 DefaultPort: 기본으로 연결, 바인딩될 포트 DefaultBindAddress: 서버모드에서 기본으로 바인딩할 IP DefaultRemoteAddress: 클라이언트에서 기본으로 연결을 시도할 서버의 주소 DefaultProtocol: 사용할 Protocol

View Source
const (
	ServerMode = 0
	ClientMode = 1
)

서버로 사용하고싶으면 0, 클라이언트로 사용하고싶으면 1

View Source
const (
	TCP      = 0
	SocketIO = 1
)

TCP를 통해 연결하고 싶으면 0, socket.io로 연결하고 싶으면 1

Variables

View Source
var Clients []Client

Clients : 클라이언트가 연결되면 Client 형식으로 저장한다.

View Source
var ServerConnection net.Conn

ServerConnection : 클라이언트 모드에서 연결된 서버의 연결객체

Functions

func Binder

func Binder(wg *sync.WaitGroup, BindAddr string, Port uint)

Binder func ServerMode에서 TCP를 바인딩하여 요청을 requestHandler로 전달해주는 함수

func CallLocalFunc

func CallLocalFunc(wg *sync.WaitGroup, name string, params ...Any) (result []reflect.Value, err error)

CallLocalFunc func RegisterFunc 로 등록된 함수가 원격에서 함수를 호출했을때 이함수를 통해 실행된다

func CallRemoteFunc

func CallRemoteFunc(FunctionName string, args ...Any)

CallRemoteFunc func 연결된 (서버)의 함수를 호출하고 싶을때 사용하는 함수 json형식으로 변환해서 tcp로 서버에 전달.

func ConnectToRemote

func ConnectToRemote(Protocol uint)

ConnectToRemote func 클라이언트로 사용할경우 서버에 연결할때 사용하는 함수 무슨 Protocol로 연결할지 정해야한다

func Listener

func Listener(wg *sync.WaitGroup, BindAddr string, Port uint)

Listener func ServerMode 일때 tcp대신 socket.io 사용 구현 덜됨;;

func RandStringRunes

func RandStringRunes(n int) string

RandStringRunes func 랜덤 문자열 생성 함수

func RegisterFunc

func RegisterFunc(FuncName string, Function interface{})

RegisterFunc func CallLocalFunc 함수에 의해 실행될 수 있는, 즉 원격에서 호출가능한 함수를 등록하는 함수 funcs 맵에 등록되며 이 함수에 등록되지 않은 함수는 원격에서 호출할 수 없다.

func SetBindAddress

func SetBindAddress(BindAddress string)

SetBindAddress func StartServer로 ServerMode 로 실행할때 바인드될 아이피 주소. ""로 설정하면 모든 NIC에 바인딩된다. 이 함수를 호출하지 않으면 DefaultBindAddress인 127.0.0.1로 바인딩된다.

func SetBindPort

func SetBindPort(BindPort uint)

SetBindPort func StartServer로 ServerMode 로 실행할때 바인드될 포트 번호. 이 함수를 호출하지 않으면 DefaultPortd인 8787로 바인딩된다.

func SetRemoteAddress

func SetRemoteAddress(ServerAddress string)

SetRemoteAddress func 연결할 서버의 주소를 설정하는 함수. 호출하지 않으면 DefaultRemoteAddress인 127.0.0.1이 설정된다

func SetRemotePort

func SetRemotePort(ServerPort uint)

SetRemotePort func 연결할 서버의 포트를 설정하는 함수. 호출하지 않으면 DefaultPort인 8787이 설정된다

func StartServer

func StartServer(Protocol uint)

StartServer func 프로그램을 서버역할로 사용하려면 이 함수를 호출 시작되면 Binder 함수를 비동기로 호출하여 비동기로 tcp Listen 혹은 socket.io 를 사용할 수 있음 이 함수가 호출되면 무조건 Mode가 ServerMode 로 바뀐다 Protocol로 TCP를 사용할 것인지 socket.io 를 사용할 것인지 정해야 한다 0은 TCP, 1은 socket.io

Types

type Any

type Any interface{}

Any struct 모든 형식의 값을 다 받기위한 interface

type CallEvent

type CallEvent struct {
	FunctionName string
	Params       []Any
}

CallEvent struct TCP에서 함수 호출시 사용하는 이벤트 구조

type Client

type Client struct {
	Socket     socketio.Socket
	Connection net.Conn
	ClientID   string
}

Client struct 서버모드에서 연결된 클라이언트를 저장할 구조 socket.io를 사용할 경우에는 Connection 값이 비고, TCP를 사용할 경우 Socket 값이 빈다.

type Info

type Info struct {
	BindPort      uint
	BindAddress   string
	RemotePort    uint
	RemoteAddress string
	Mode          uint
	Protocol      uint
}

Info struct PostBird 에서 사용될 값들

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL