您确定要退出登录吗?

修改密码

原密码
新密码
确认新密码
客服微信
产品咨询

tio-websocket-server

talent-tan


框架/工具 t-io tio

框架简介

tio-websocket-server是基于t-io实现的websocket服务器,自带t-io提供的各项API以及一流的性能和稳定性

示范工程

https://gitee.com/tywo45/tio-websocket-showcase

框架部分代码

public WsRequest decode(ByteBuffer buffer, int limit, int position, int readableLength,
	    ChannelContext channelContext) throws TioDecodeException {
	WsSessionContext wsSessionContext = (WsSessionContext) channelContext.get();
	// int initPosition = buffer.position();

	if (!wsSessionContext.isHandshaked()) {// 尚未握手
	    HttpRequest request = HttpRequestDecoder.decode(buffer, limit, position, readableLength, channelContext,
		    wsServerConfig);
	    if (request == null) {
		return null;
	    }

	    HttpResponse httpResponse = updateWebSocketProtocol(request, channelContext);
	    if (httpResponse == null) {
		throw new TioDecodeException("http协议升级到websocket协议失败");
	    }

	    wsSessionContext.setHandshakeRequest(request);
	    wsSessionContext.setHandshakeResponse(httpResponse);

	    WsRequest wsRequestPacket = new WsRequest();
	    // wsRequestPacket.setHeaders(httpResponse.getHeaders());
	    // wsRequestPacket.setBody(httpResponse.getBody());
	    wsRequestPacket.setHandShake(true);

	    return wsRequestPacket;
	}


登录 和大家一起讨论吧!

重置 发表评论


确定要删除该条评论吗?

案例不存在!