• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Net类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.badlogic.gdx.Net的典型用法代码示例。如果您正苦于以下问题:Java Net类的具体用法?Java Net怎么用?Java Net使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Net类属于com.badlogic.gdx包,在下文中一共展示了Net类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: downloadFileFromDrive

import com.badlogic.gdx.Net; //导入依赖的package包/类
protected void downloadFileFromDrive(String url, final ILoadGameStateResponseListener responseListener) {
    Net.HttpRequest httpRequest = new Net.HttpRequest(Net.HttpMethods.GET);
    httpRequest.setUrl(url);
    httpRequest.setHeader("Authorization", "Bearer " + oAuthToken);
    Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() {
        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            byte[] result = httpResponse.getResultAsString().getBytes();
            responseListener.gsGameStateLoaded(result);
        }

        @Override
        public void failed(Throwable t) {
            responseListener.gsGameStateLoaded(null);
        }

        @Override
        public void cancelled() {
            responseListener.gsGameStateLoaded(null);
        }
    });
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:23,代码来源:GpgsClient.java


示例2: loadFileFromDriveV3

import com.badlogic.gdx.Net; //导入依赖的package包/类
/**
 * this can be used instead of loadFileFromDrive/downloadFileFromDrive... but it does not work on Firefox
 * Firefox does not follow a redirect that is given back to the real download url
 * @param driveFileId
 * @param responseListener
 */
protected void loadFileFromDriveV3(String driveFileId, final ILoadGameStateResponseListener responseListener) {
    Net.HttpRequest httpRequest = new Net.HttpRequest(Net.HttpMethods.GET);
    httpRequest.setUrl("https://content.googleapis.com/drive/v3/files/" + driveFileId + "?alt=media");
    httpRequest.setHeader("Authorization", "Bearer " + oAuthToken);
    Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() {
        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            byte[] result = httpResponse.getResultAsString().getBytes();
            responseListener.gsGameStateLoaded(result);
        }

        @Override
        public void failed(Throwable t) {
            responseListener.gsGameStateLoaded(null);
        }

        @Override
        public void cancelled() {
            responseListener.gsGameStateLoaded(null);
        }
    });
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:29,代码来源:GpgsClient.java


示例3: sendOpenSessionEvent

import com.badlogic.gdx.Net; //导入依赖的package包/类
protected void sendOpenSessionEvent() {
    if (!isSessionActive())
        return;

    Map<String, String> params = new HashMap<String, String>();
    addGameIDUserNameUserToken(params);

    final Net.HttpRequest http = buildJsonRequest("sessions/open/", params);

    if (http != null)
        Gdx.net.sendHttpRequest(http, new NoOpResponseListener());

    pingTask = Timer.schedule(new Timer.Task() {
        @Override
        public void run() {
            sendKeepSessionOpenEvent();
        }
    }, GJ_PING_INTERVAL, GJ_PING_INTERVAL);

}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:21,代码来源:GameJoltClient.java


示例4: initializeOrResetEventKey

import com.badlogic.gdx.Net; //导入依赖的package包/类
/**
 * Use careful! It resets your event to 0. Needed for first time initialization.
 *
 * @param eventId
 */
public void initializeOrResetEventKey(String eventId) {
    if (!initialized) {
        Gdx.app.error(GAMESERVICE_ID, "Cannot submit event: set app ID via initialize() first");
        return;
    }
    if (eventKeyPrefix == null) {
        Gdx.app.log(GAMESERVICE_ID, "No event key prefix provided.");
        return;
    }

    // no user name or token added! We want to use the global storage.
    // http://gamejolt.com/api/doc/game/data-store/set
    Net.HttpRequest http = buildStoreDataRequest(eventKeyPrefix + eventId, true, "0");

    if (http != null)
        Gdx.net.sendHttpRequest(http, new NoOpResponseListener());

}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:24,代码来源:GameJoltClient.java


示例5: buildStoreDataRequest

import com.badlogic.gdx.Net; //导入依赖的package包/类
/**
 * content must be without special chars ampersand or question mark - use Base64 when not sure!
 */
protected Net.HttpRequest buildStoreDataRequest(String dataKey, boolean globalKey, String content) {
    Map<String, String> params = new HashMap<String, String>();

    if (globalKey)
        params.put("game_id", gjAppId);
    else
        addGameIDUserNameUserToken(params);
    params.put("key", dataKey);

    final Net.HttpRequest http = buildJsonRequest("data-store/set/", params);
    if (http == null)
        return null;

    http.setMethod(Net.HttpMethods.POST);
    http.setHeader("Content-Type", "application/x-www-form-urlencoded");
    http.setContent("data=" + content);

    return http;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:23,代码来源:GameJoltClient.java


示例6: buildRequest

import com.badlogic.gdx.Net; //导入依赖的package包/类
protected Net.HttpRequest buildRequest(String component, Map<String, String> params) {
    String request = GJ_GATEWAY + component;
    request += HttpParametersUtils.convertHttpParameters(params);

    /* Generate signature */
    final String signature;
    try {
        signature = md5(request + gjAppPrivateKey);
    } catch (Exception e) {
        /* Do not leak 'gamePrivateKey' in log */
        Gdx.app.error(GAMESERVICE_ID, "Cannot honor request: " + request, e);
        return null;
    }
    /* Append signature */
    String complete = request;
    complete += "&";
    complete += "signature";
    complete += "=";
    complete += signature;

    final Net.HttpRequest http = new Net.HttpRequest();
    http.setMethod(Net.HttpMethods.GET);
    http.setUrl(complete);

    return http;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:27,代码来源:GameJoltClient.java


示例7: getTicket

import com.badlogic.gdx.Net; //导入依赖的package包/类
public static void getTicket(final WebSocketLocal webSocket){
    final JSONObject[] finalResult = new JSONObject[1];
    String accesToken = Gdx.app.getPreferences("informationLog").getString("accesstoken");
    HttpRequestBuilder buider = new HttpRequestBuilder();
    Net.HttpRequest request = buider.newRequest().url(api_url + d_login).method(Net.HttpMethods.POST).build();
    request.setHeader("Authorization", "Bearer " + accesToken);
    Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            String r = httpResponse.getResultAsString();
            webSocket.connectWebSocket(new JSONObject(r));
            Gdx.app.log("response", "ticket "+r);
        }

        @Override
        public void failed(Throwable t) {
            webSocket.connectWebSocket(new JSONObject());
        }

        @Override
        public void cancelled() {
            webSocket.connectWebSocket(new JSONObject());
        }
    });
}
 
开发者ID:TudorRosca,项目名称:enklave,代码行数:26,代码来源:RequestTokenSocket.java


示例8: makeRequestEnklave

import com.badlogic.gdx.Net; //导入依赖的package包/类
public void makeRequestEnklave(){
    Preferences pref = Gdx.app.getPreferences("informationLog");
    String acces = pref.getString("accesstoken");
    HttpRequestBuilder builder = new HttpRequestBuilder();
    Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.GET).url(url + enkNearby).build();
    request.setHeader("Authorization", "Bearer " + acces);
    Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            String response = httpResponse.getResultAsString();
            JSONArray jsonArray = new JSONArray(response);
            ListEnklaves.getInstance().setListEnklave(jsonArray);
            Gdx.app.log("response enklave : " + httpResponse.getStatus().getStatusCode(), " message " +response);
        }

        @Override
        public void failed(Throwable t) {
            Gdx.app.log("response : " + t.getMessage(), "fdg " + t.getLocalizedMessage());
        }

        @Override
        public void cancelled() {
            Gdx.app.log("response ","cancelled");
        }
    });
}
 
开发者ID:TudorRosca,项目名称:enklave,代码行数:27,代码来源:NearbyEnklave.java


示例9: postAndWait

import com.badlogic.gdx.Net; //导入依赖的package包/类
public static Object postAndWait(final ResultType type, final Net.HttpRequest request, final ICancel icancel) {
log.debug("Send Post request");
final AtomicBoolean WAIT = new AtomicBoolean(true);
final Object[] result = new Object[1];
if(icancel!=null){
    CB.postAsync(new Runnable() {
        @Override
        public void run() {
            while (WAIT.get()) {
                if (icancel.cancel()) {
                    Gdx.net.cancelHttpRequest(request);
                }
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

final AtomicBoolean isRedirection = new AtomicBoolean(false);
Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
 
开发者ID:Longri,项目名称:cachebox3.0,代码行数:25,代码来源:NetUtils.java


示例10: sendVotes

import com.badlogic.gdx.Net; //导入依赖的package包/类
public static Boolean sendVotes(String User, String password, int vote, String url, String waypoint, ICancel icancel) {
    String guid = url.substring(url.indexOf("guid=") + 5).trim();

    String data = "userName=" + User + "&password=" + password + "&voteUser=" + String.valueOf(vote / 100.0) + "&cacheId=" + guid + "&waypoint=" + waypoint;

    try {
        Net.HttpRequest httpPost = new Net.HttpRequest(Net.HttpMethods.POST);
        httpPost.setUrl("http://gcvote.de/getVotes.php");
        httpPost.setTimeOut(Config.socket_timeout.getValue());
        httpPost.setContent(data);


        String responseString = (String) NetUtils.postAndWait(NetUtils.ResultType.STRING, httpPost, icancel);

        return responseString.equals("OK\n");

    } catch (Exception ex) {
        return false;
    }
}
 
开发者ID:Longri,项目名称:cachebox3.0,代码行数:21,代码来源:GCVote.java


示例11: handleHttpResponse

import com.badlogic.gdx.Net; //导入依赖的package包/类
@Override
public void handleHttpResponse(Net.HttpResponse httpResponse) {
    try {
        handleResponse(httpResponse.getResultAsString());
        if (statsReporterResponseListener != null) {
            statsReporterResponseListener.succeed(responseVO);
        }
    } catch (Error error) {
        Gdx.app.error(TAG, error.getMessage());
        if (statsReporterResponseListener != null) {
            statsReporterResponseListener.failed(error);
        }
    } catch (SerializationException e) {
        e.printStackTrace();
        if (statsReporterResponseListener != null) {
            statsReporterResponseListener.failed(e);
        }
    }
}
 
开发者ID:UnderwaterApps,项目名称:submarine,代码行数:20,代码来源:StatsReporter.java


示例12: sendRequest

import com.badlogic.gdx.Net; //导入依赖的package包/类
protected void sendRequest(String method, Map<String, String> params, final NetworkListener listener){
    HttpRequest httpPost = new HttpRequest(HttpMethods.POST);
    httpPost.setUrl(website + method + ".php");
    httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    httpPost.setContent(HttpParametersUtils.convertHttpParameters(params));

    Gdx.net.sendHttpRequest (httpPost, new HttpResponseListener() {
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            String responce = new String(httpResponse.getResult());
            String dat = decrypt(responce, ENC_KEY);
            listener.finished(dat);
            listener.length(dat.getBytes().length);
        }

        public void failed(Throwable t) {
            listener.failed(t);
        }

        public void cancelled(){

        }
    });
}
 
开发者ID:Xemplar,项目名称:NerdShooter,代码行数:24,代码来源:NetworkHandle.java


示例13: CardshifterNonGWTClient

import com.badlogic.gdx.Net; //导入依赖的package包/类
public CardshifterNonGWTClient(CardshifterPlatform platform, String host, int port,
     CardshifterMessageHandler handler, LoginMessage loginMessage) {
    socket = Gdx.net.newClientSocket(Net.Protocol.TCP, host, port, new SocketHints());
    output = socket.getOutputStream();
    input = socket.getInputStream();
    transformer = new ByteTransformer(new GdxLogger(), new GdxReflection());
    this.handler = handler;
    try {
        output.write("{ \"command\": \"serial\", \"type\": \"1\" }".getBytes());
        output.flush();
        Gdx.app.log("Client", "Sent serial type");
        platform.setupLogging();
        send(loginMessage);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    new Thread(this).start();
}
 
开发者ID:Cardshifter,项目名称:Cardshifter,代码行数:20,代码来源:CardshifterNonGWTClient.java


示例14: ClientSocket

import com.badlogic.gdx.Net; //导入依赖的package包/类
public ClientSocket(Net.Protocol protocol, String host, int port, SocketHints hints) {
	try {
		// create the socket
		socket = new java.net.Socket();
		applyHints(hints);  // better to call BEFORE socket is connected!

		// and connect...
		InetSocketAddress address = new InetSocketAddress(host, port);
		if (hints != null) {
			socket.connect(address, hints.connectTimeout);
		} else {
			socket.connect(address);
		}
	} catch (Exception e) {
		throw new GdxRuntimeException("Error making a socket connection to " + host + ":" + port, e);
	}
}
 
开发者ID:Olloth,项目名称:LibGDXServer,代码行数:18,代码来源:ClientSocket.java


示例15: buildQueryStatRequest

import com.badlogic.gdx.Net; //导入依赖的package包/类
/**
 * override this method for tunneling through own server or other needs
 */
protected Net.HttpRequest buildQueryStatRequest(Integer statId, boolean playerRelated) {
    String url = "https://api.kongregate.com/api/high_scores/" +
            (playerRelated && isSessionActive() ? "friends/" + statId.toString() + "/" + Integer.toString(getUserId())
                    : "https://api.kongregate.com/api/high_scores/lifetime/" + statId.toString())
            + ".json";

    Net.HttpRequest http = new Net.HttpRequest();
    http.setMethod(Net.HttpMethods.GET);
    http.setUrl(url);

    return http;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:16,代码来源:KongClient.java


示例16: saveFileToDrive

import com.badlogic.gdx.Net; //导入依赖的package包/类
protected void saveFileToDrive(String fileName, String driveFileId, byte[] gameState, final ISaveGameStateResponseListener success) {
    String request = "--" + CONTENT_BOUNDARY + "\n" +
            "Content-Type: application/json; charset=UTF-8\n" +
            "\n" +
            "{\"name\": \"" + fileName + "\", \"parents\": [\"appDataFolder\"]}\n" +
            "\n" +
            "--" + CONTENT_BOUNDARY + "\n" +
            "Content-Type: application/octet-stream\n" +
            "\n" + new String(gameState) +
            "\n--" + CONTENT_BOUNDARY + "--";

    Net.HttpRequest httpRequest;
    if (driveFileId == null) {
        // create new file
        httpRequest = new Net.HttpRequest(Net.HttpMethods.POST);
        httpRequest.setUrl("https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart");
    } else {
        //v3 needs PATCH and PATCH is not supported by libgdx, so use v2 and PUT
        httpRequest = new Net.HttpRequest(Net.HttpMethods.PUT);
        httpRequest.setUrl("https://www.googleapis.com/upload/drive/v2/files/" + driveFileId + "?uploadType=multipart");
    }
    httpRequest.setHeader("Authorization", "Bearer " + oAuthToken);
    httpRequest.setHeader("Content-Type", "multipart/related; boundary=" + CONTENT_BOUNDARY);
    //httpRequest.setHeader("Content-Length", String.valueOf(request.length()));
    httpRequest.setContent(request);
    Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() {
        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            if (success != null)
                success.onGameStateSaved(true, null);
        }

        @Override
        public void failed(Throwable t) {
            if (success != null)
                success.onGameStateSaved(false, t.getMessage());
        }

        @Override
        public void cancelled() {
            if (success != null)
                success.onGameStateSaved(true, "CANCELLED");
        }
    });
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:46,代码来源:GpgsClient.java


示例17: submitEvent

import com.badlogic.gdx.Net; //导入依赖的package包/类
@Override
public boolean submitEvent(String eventId, int increment) {

    if (!initialized) {
        Gdx.app.error(GAMESERVICE_ID, "Cannot submit event: set app ID via initialize() first");
        return false;
    }
    if (eventKeyPrefix == null) {
        Gdx.app.log(GAMESERVICE_ID, "No event logged - no event key prefix provided.");
        return false;
    }

    Map<String, String> params = new HashMap<String, String>();
    // no user name or token added! We want to use the global storage.
    // http://gamejolt.com/api/doc/game/data-store/update
    params.put("game_id", gjAppId);
    params.put("key", eventKeyPrefix + eventId);
    params.put("value", Integer.toString(increment));
    params.put("operation", "add");

    final Net.HttpRequest http = buildJsonRequest("data-store/update/", params);
    if (http == null)
        return false;

    Gdx.net.sendHttpRequest(http, new NoOpResponseListener());

    return true;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:29,代码来源:GameJoltClient.java


示例18: unlockAchievement

import com.badlogic.gdx.Net; //导入依赖的package包/类
@Override
public boolean unlockAchievement(String achievementId) {
    if (trophyMapper == null) {
        Gdx.app.log(GAMESERVICE_ID, "Cannot unlock achievement: No mapper for trophy ids provided.");
        return false;
    }

    if (!isSessionActive())
        return false;

    Integer trophyId = trophyMapper.mapToGsId(achievementId);

    // no board available or not connected
    if (trophyId == null)
        return false;

    Map<String, String> params = new HashMap<String, String>();
    addGameIDUserNameUserToken(params);
    params.put("trophy_id", String.valueOf(trophyId));

    final Net.HttpRequest http = buildJsonRequest("trophies/add-achieved/", params);
    if (http == null)
        return false;

    Gdx.net.sendHttpRequest(http, new NoOpResponseListener());

    return true;
}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:29,代码来源:GameJoltClient.java


示例19: buildLoadDataRequest

import com.badlogic.gdx.Net; //导入依赖的package包/类
/**
 * Load data is done with dump format
 */
protected Net.HttpRequest buildLoadDataRequest(String dataKey, boolean globalKey) {
    Map<String, String> params = new HashMap<String, String>();

    if (globalKey)
        params.put("game_id", gjAppId);
    else
        addGameIDUserNameUserToken(params);
    params.put("key", dataKey);

    final Net.HttpRequest http = buildRequest("data-store/?format=dump&", params);

    return http;

}
 
开发者ID:MrStahlfelge,项目名称:gdx-gamesvcs,代码行数:18,代码来源:GameJoltClient.java


示例20: sendMessage

import com.badlogic.gdx.Net; //导入依赖的package包/类
public void sendMessage(String message){
    final Preferences pref = Gdx.app.getPreferences("informationLog");
    String acces = pref.getString("accesstoken");
    JSONObject json = new JSONObject();
    json.accumulate("txt",message);
    HttpRequestBuilder builder = new HttpRequestBuilder();
    Net.HttpRequest request = builder.newRequest().method(Net.HttpMethods.POST).url(url + join).build();
    request.setHeader("Authorization", "Bearer " + acces);
    request.setHeader("Content-type", "application/json");
    request.setContent(json.toString());
    Gdx.net.sendHttpRequest(request, new Net.HttpResponseListener() {
        @Override
        public void handleHttpResponse(Net.HttpResponse httpResponse) {
            //Gdx.app.log("response :"+httpResponse.getStatus().getStatusCode(),"message "+httpResponse.getResultAsString());
        }

        @Override
        public void failed(Throwable t) {
            //Gdx.app.log("response :","failed "+t);
        }

        @Override
        public void cancelled() {
            //Gdx.app.log("response :","cancel ");
        }
    });
}
 
开发者ID:TudorRosca,项目名称:enklave,代码行数:28,代码来源:SendFaction.java



注:本文中的com.badlogic.gdx.Net类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FabricConnection类代码示例发布时间:2022-05-21
下一篇:
Java FunctionQuery类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap