Permalink
Browse files

improving tests

  • Loading branch information...
MattTuttle committed Feb 19, 2014
1 parent 5937242 commit 32bd68dcd6001b1f495efba7fbf07716a60da35b
@@ -86,18 +86,18 @@ class WebSocket extends BaseProtocol
switch (frame.opcode)
{
case 0x0: // continuation
case WebSocket.OPCODE_CONTINUE: // continuation
// return frame.bytes.toString();
throw "Continuation should be handled by recvFrame()";
case 0x1: // text
case WebSocket.OPCODE_TEXT: // text
recvText(frame.bytes.toString());
case 0x2: // binary
case WebSocket.OPCODE_BINARY: // binary
recvBinary(frame.bytes);
case 0x8: // close
case WebSocket.OPCODE_CLOSE: // close
cnx.close();
case 0x9: // ping
sendFrame(0xA); // send pong
case 0xA: // pong
case WebSocket.OPCODE_PING: // ping
sendFrame(WebSocket.OPCODE_PONG); // send pong
case WebSocket.OPCODE_PONG: // pong
// do nothing
default:
throw "Unsupported websocket opcode: " + frame.opcode;
View
@@ -16,11 +16,11 @@ class Client implements hxnet.interfaces.IClient
public function new()
{
buffer = Bytes.alloc(1024);
client = new UdpSocket();
}
public function connect(?hostname:String, port:Null<Int> = 12800)
{
client = new UdpSocket();
var host:Host = new Host(hostname == null ? Host.localhost() : hostname);
address = new Address();
address.host = host.ip;
@@ -31,7 +31,7 @@ class Client implements hxnet.interfaces.IClient
public function update()
{
if (client == null) return;
if (client == null || protocol == null) return;
try
{
@@ -49,22 +49,30 @@ class Client implements hxnet.interfaces.IClient
}
catch (e:haxe.io.Error)
{
// End of stream
}
}
public function close()
{
client.close();
client = null;
connection = null;
protocol.loseConnection();
protocol = null;
}
private function get_connected():Bool
{
return client != null;
}
private function set_protocol(value:IProtocol):IProtocol
{
blocking = value.isBlocking();
if (client != null)
{
value.makeConnection(new Connection(client));
value.makeConnection(new Connection(client, address));
client.setBlocking(blocking);
}
protocol = value;
View
@@ -4,6 +4,8 @@ import neko.vm.Thread;
import cpp.vm.Thread;
#end
import protocol.PingPong;
class TcpTest extends haxe.unit.TestCase
{
public function createRPCServer()
@@ -1,4 +1,4 @@
class NetTest
class TestMain
{
public static function main()
{
View
@@ -4,13 +4,15 @@ import neko.vm.Thread;
import cpp.vm.Thread;
#end
import protocol.PingPong;
class UdpTest extends haxe.unit.TestCase
{
public function createRPCServer()
{
var port = Thread.readMessage(true);
var server = new hxnet.udp.Server(PingPong, port);
while (Thread.readMessage(false) == null)
while (Thread.readMessage(false) != "finish")
{
server.update();
}
View
@@ -1,4 +1,4 @@
-x NetTest
-x TestMain
-lib hxnet
-D mac
@@ -1,3 +1,5 @@
package protocol;
import hxnet.protocols.RPC;
// super simple ping/pong protocol

0 comments on commit 32bd68d

Please sign in to comment.