Commit da4e391d authored by AlexStocks's avatar AlexStocks

test getty compression feature

parent a5e8e4e4
# ws-echo #
---
*getty tcp examples of Echo Example*
## LICENSE ##
---
> LICENCE : Apache License 2.0
## develop history ##
---
- 2016/11/19
> 1 add client/app/config.go:GettySessionParam{CompressEncoding} to test compress websocket compression extension.
>
> 2 add server/app/config.go:GettySessionParam{CompressEncoding} to test compress websocket compression extension.
......@@ -69,7 +69,7 @@ func (this *EchoClient) selectSession() *getty.Session {
defer this.lock.RUnlock()
count := len(this.sessions)
if count == 0 {
log.Info("client session arrray is nil...")
log.Info("client session array is nil...")
return nil
}
......
......@@ -33,19 +33,20 @@ var (
type (
GettySessionParam struct {
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
CompressEncoding bool `default:"false"`
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
}
// Config holds supported types by the multiconfig package
......
......@@ -75,6 +75,10 @@ func newSession(session *getty.Session) error {
tcpConn *net.TCPConn
)
if conf.GettySessionParam.CompressEncoding {
session.SetCompressType(getty.CompressZip)
}
if tcpConn, ok = session.Conn().(*net.TCPConn); !ok {
panic(fmt.Sprintf("%s, session.conn{%#v} is not tcp connection\n", session.Stat(), session.Conn()))
}
......
......@@ -7,7 +7,7 @@ AppName = "ECHO-CLIENT"
LocalHost = "127.0.0.1"
# server
ServerHost = "192.168.35.1"
ServerHost = "192.168.8.3"
ServerPort = 10000
ProfilePort = 10080
......@@ -34,6 +34,7 @@ FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
TcpRBufSize = 262144
......
......@@ -33,19 +33,20 @@ var (
type (
GettySessionParam struct {
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
CompressEncoding bool `default:"false"`
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
}
// Config holds supported types by the multiconfig package
......
......@@ -80,6 +80,10 @@ func newSession(session *getty.Session) error {
tcpConn *net.TCPConn
)
if conf.GettySessionParam.CompressEncoding {
session.SetCompressType(getty.CompressZip)
}
if tcpConn, ok = session.Conn().(*net.TCPConn); !ok {
panic(fmt.Sprintf("%s, session.conn{%#v} is not tcp connection\n", session.Stat(), session.Conn()))
}
......
......@@ -4,7 +4,8 @@
AppName = "ECHO-SERVER"
# Host = "127.0.0.1"
Host = "192.168.35.1"
# Host = "192.168.35.1"
Host = "192.168.8.3"
Ports = ["10000", "20000"]
ProfilePort = 10086
......@@ -18,6 +19,7 @@ FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
TcpRBufSize = 262144
......
# ws-echo #
---
*getty websocket code examples of Echo Example*
## LICENSE ##
---
> LICENCE : Apache License 2.0
## develop history ##
---
- 2016/11/19
> 1 add client/app/config.go:GettySessionParam{CompressEncoding} to test compress websocket compression extension.
>
> 2 add server/app/config.go:GettySessionParam{CompressEncoding} to test compress websocket compression extension.
>
> 3 Pls attention that ie does not support weboscket compression extension while the latest chrome support it while echo/ws-echo/server enable websocket compress function. I have not test firefox and edge.
......@@ -68,7 +68,7 @@ func (this *EchoClient) selectSession() *getty.Session {
defer this.lock.RUnlock()
count := len(this.sessions)
if count == 0 {
log.Info("client session arrray is nil...")
log.Info("client session array is nil...")
return nil
}
......
......@@ -33,19 +33,20 @@ var (
type (
GettySessionParam struct {
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
CompressEncoding bool `default:"false"`
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
}
// Config holds supported types by the multiconfig package
......
......@@ -79,6 +79,12 @@ func newSession(session *getty.Session) error {
panic(fmt.Sprintf("%s, session.conn{%#v} is not tcp connection\n", session.Stat(), session.Conn()))
}
if conf.GettySessionParam.CompressEncoding {
session.SetCompressType(getty.CompressZip)
}
// else {
// session.SetCompressType(getty.CompressNone)
//}
tcpConn.SetNoDelay(conf.GettySessionParam.TcpNoDelay)
tcpConn.SetKeepAlive(conf.GettySessionParam.TcpKeepAlive)
tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize)
......
#!/usr/bin/env bash
# ******************************************************
# DESC : build script for test env
# AUTHOR : Alex Stocks
# VERSION : 1.0
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-07-12 16:34
# FILE : test.sh
# ******************************************************
set -e
export GOOS=windows
export GOARCH=386
PROFILE=test
PROJECT_HOME=`pwd`
if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then
. ${PROJECT_HOME}/assembly/common/app.properties
fi
if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then
. ${PROJECT_HOME}/assembly/common/build.sh
fi
......@@ -7,7 +7,8 @@ AppName = "ECHO-CLIENT"
LocalHost = "127.0.0.1"
# server
ServerHost = "192.168.35.1"
# ServerHost = "127.0.0.1"
ServerHost = "192.168.8.3"
ServerPort = 10000
ServerPath = "/echo"
ProfilePort = 10080
......@@ -26,15 +27,18 @@ SessionTimeout = "20s"
# client
# client echo request string
EchoString = "Hello, getty!"
# EchoString = "Hello, getty!"
# for compress test
EchoString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
# 发送echo请求次数
EchoTimes = 10000
EchoTimes = 1
# app fail fast
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
TcpRBufSize = 262144
......
var serverAddress = '192.168.8.3:10000';
// var serverAddress = '127.0.0.1:10000';
......@@ -17,6 +17,7 @@
<script src="jquery-1.10.2.min.js"></script>
<script src="encoding.js"></script>
<script src="struct.min.js"></script>
<script src="addr.js"></script>
<script src="main.js"></script>
</body>
</html>
......@@ -39,7 +39,8 @@ $(function() {
var $chatPage = $('.chat.page'); // The chatroom page
var socket = new WebSocket('ws://192.168.35.1:10000/echo');
// var socket = new WebSocket('ws://192.168.35.1:10000/echo');
var socket = new WebSocket('ws://' + serverAddress + '/echo');
// // Setting binaryType to accept received binary as either 'blob' or 'arraybuffer'. In default it is 'blob'.
// socket.binaryType = 'arraybuffer';
// socket.binaryType = ''
......
......@@ -33,19 +33,20 @@ var (
type (
GettySessionParam struct {
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
CompressEncoding bool `default:"false"` // Accept-Encoding: gzip, deflate, sdch
TcpNoDelay bool `default:"true"`
TcpKeepAlive bool `default:"true"`
TcpRBufSize int `default:"262144"`
TcpWBufSize int `default:"65536"`
PkgRQSize int `default:"1024"`
PkgWQSize int `default:"1024"`
TcpReadTimeout string `default:"1s"`
tcpReadTimeout time.Duration
TcpWriteTimeout string `default:"5s"`
tcpWriteTimeout time.Duration
WaitTimeout string `default:"7s"`
waitTimeout time.Duration
SessionName string `default:"echo-client"`
}
// Config holds supported types by the multiconfig package
......
......@@ -84,6 +84,12 @@ func newSession(session *getty.Session) error {
panic(fmt.Sprintf("%s, session.conn{%#v} is not tcp connection\n", session.Stat(), session.Conn()))
}
if conf.GettySessionParam.CompressEncoding {
session.SetCompressType(getty.CompressZip)
}
// else {
// session.SetCompressType(getty.CompressNone)
// }
tcpConn.SetNoDelay(conf.GettySessionParam.TcpNoDelay)
tcpConn.SetKeepAlive(conf.GettySessionParam.TcpKeepAlive)
tcpConn.SetReadBuffer(conf.GettySessionParam.TcpRBufSize)
......
......@@ -3,8 +3,9 @@
AppName = "ECHO-SERVER"
Host = "0.0.0.0"
# Host = "127.0.0.1"
Host = "192.168.35.1"
# Host = "192.168.35.1"
Ports = ["10000", "20000"]
Paths = ["/echo", "/echo"]
ProfilePort = 10086
......@@ -22,6 +23,7 @@ FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
TcpRBufSize = 262144
......
# getty #
# getty examples ##
---
*a netty like asynchronous network I/O library*
*[getty](https://github.com/alexstocks/getty) code examples*
> getty-examples alse shows a java like compile package.
## license ##
---
Apache License 2.0
## getty examples ##
---
*getty examples是基于getty的实现的代码示例*
> getty-examples借鉴java的编译思路,提供了区别于一般的go程序的而类似于java的独特的编译脚本系统。
### getty example1: tcp-echo ###
## getty example1: tcp-echo ##
---
This example shows a simple tcp client and server.
The server echoes messages sent to it. The client sends messages to the echo server
and prints all messages received.
The server sends back messages from client. The client sends messages to the echo server and prints all messages received.
To run the example, start the server:
$ cd tcp-echo/server/ && sh assembly/linux/test.sh && cd target/linux/echo_server-0.3.07-20161009-1632-test/ && sh bin/load.sh start
$ cd echo/tcp-echo/server/ && sh assembly/linux/test.sh && cd target/linux/echo_server-0.3.07-20161009-1632-test/ && sh bin/load.sh start
Next, start the client:
$ cd tcp-echo/client/ && sh assembly/linux/test.sh && cd target/linux/echo_client-0.3.07-20161009-1634-test/ && sh bin/load.sh start
### getty example1: ws-echo ###
## getty example1: ws-echo ##
---
This example shows a simple websocket client and server.
This example shows a simple websocket client(go client & javascript client) and server.
The server sends back messages from client. The client sends messages to the echo server and prints all messages received.
To run the example, start the server:
$ cd echo/ws-echo/server/ && sh assembly/linux/test.sh && cd target/linux/echo_server-0.3.07-20161009-1632-test/ && sh bin/load.sh start
Next, start the go client:
$ cd echo/ws-echo/client/ && sh assembly/linux/test.sh && cd target/linux/echo_client-0.3.07-20161009-1634-test/ && sh bin/load.sh start
Or start the js client:
$ cd echo/ws-echo/js-client/ && open index.html in a internet browser(like chrome or ie or firefox etc).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment