示例#1
0
    public void OnWebSocketWithThriftServiceTestClick()
    {
        WebSocket ws = new WebSocket("ws://127.0.0.1:8092/chat/1");

        ws.OnMessage += (sender, e) => {
            MemoryStream stream = new MemoryStream(e.RawData);
            Thrift.Protocol.TProtocol        tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(stream, null));
            idl.MultiplicationService.Client client    = new idl.MultiplicationService.Client(tProtocol);
            int aa = client.recv_multiply();

            Debug.Log("recv :" + aa);
        };

        ws.OnOpen += (object sender, System.EventArgs e) => {
            MemoryStream stream = new MemoryStream(256);
            Thrift.Protocol.TProtocol        tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(null, stream));
            idl.MultiplicationService.Client client    = new idl.MultiplicationService.Client(tProtocol);
            client.send_multiply(11, 22);
            ws.SendAsync(stream.ToArray(), (bool s) => {
                Debug.Log("sent :" + s);
            });
        };

        ws.OnError += (object sender, NetworkLib.WebSocketSharp.ErrorEventArgs e) => {
            Debug.Log("error :" + e.Exception.Message);
        };

        ws.OnClose += (object sender, CloseEventArgs e) => {
            Debug.Log("close");
        };

        ws.ConnectAsync();
    }
示例#2
0
	public void OnWebSocketWithThriftServiceTestClick()
	{
		WebSocket ws = new WebSocket ("ws://127.0.0.1:8092/chat/1");
		ws.OnMessage += (sender, e) =>{
			
			MemoryStream stream = new MemoryStream(e.RawData);
			Thrift.Protocol.TProtocol tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(stream, null));
			idl.MultiplicationService.Client client = new idl.MultiplicationService.Client(tProtocol);
			int aa = client.recv_multiply();

			Debug.Log("recv :" + aa);
		};
		
		ws.OnOpen += (object sender, System.EventArgs e) => {

			MemoryStream stream = new MemoryStream(256);
			Thrift.Protocol.TProtocol tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(null, stream));
			idl.MultiplicationService.Client client = new idl.MultiplicationService.Client(tProtocol);
			client.send_multiply(11, 22);
			ws.SendAsync (stream.ToArray(), (bool s) =>{
				Debug.Log("sent :" + s);
			});
		};
		
		ws.OnError += (object sender, NetworkLib.WebSocketSharp.ErrorEventArgs e) => {
			Debug.Log("error :" + e.Exception.Message);
		};
		
		ws.OnClose += (object sender, CloseEventArgs e) => {
			Debug.Log("close");
		};
		
		ws.ConnectAsync();
	}