本文整理汇总了Java中com.badlogic.gdx.net.SocketHints类的典型用法代码示例。如果您正苦于以下问题:Java SocketHints类的具体用法?Java SocketHints怎么用?Java SocketHints使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SocketHints类属于com.badlogic.gdx.net包,在下文中一共展示了SocketHints类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: NetJavaSocketImpl
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
public NetJavaSocketImpl (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);
}
}
示例2: applyHints
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
private void applyHints (SocketHints hints) {
if (hints != null) {
try {
socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency,
hints.performancePrefBandwidth);
socket.setTrafficClass(hints.trafficClass);
socket.setTcpNoDelay(hints.tcpNoDelay);
socket.setKeepAlive(hints.keepAlive);
socket.setSendBufferSize(hints.sendBufferSize);
socket.setReceiveBufferSize(hints.receiveBufferSize);
socket.setSoLinger(hints.linger, hints.lingerDuration);
socket.setSoTimeout(hints.socketTimeout);
} catch (Exception e) {
throw new GdxRuntimeException("Error setting socket hints.", e);
}
}
}
示例3: CardshifterNonGWTClient
import com.badlogic.gdx.net.SocketHints; //导入依赖的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();
}
示例4: ClientSocket
import com.badlogic.gdx.net.SocketHints; //导入依赖的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);
}
}
示例5: applyHints
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
private void applyHints(SocketHints hints) {
if (hints != null) {
try {
socket.setPerformancePreferences(hints.performancePrefConnectionTime,
hints.performancePrefLatency,
hints.performancePrefBandwidth);
socket.setTrafficClass(hints.trafficClass);
socket.setTcpNoDelay(hints.tcpNoDelay);
socket.setKeepAlive(hints.keepAlive);
socket.setSendBufferSize(hints.sendBufferSize);
socket.setReceiveBufferSize(hints.receiveBufferSize);
socket.setSoLinger(hints.linger, hints.lingerDuration);
} catch (Exception e) {
throw new GdxRuntimeException("Error setting socket hints.", e);
}
}
}
示例6: connect
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
public boolean connect() {
if (socket != null) {
if (socket.isConnected())
return true;
}
try {
SocketHints hints = new SocketHints();
socket = Gdx.net.newClientSocket(Net.Protocol.TCP, serverAddress, serverPort, hints);
os = socket.getOutputStream();
bos = new BufferedOutputStream(os, BUFFER_SIZE);
dos = new DataOutputStream(bos);
in = socket.getInputStream();
bis = new BufferedInputStream(in, BUFFER_SIZE);
dis = new DataInputStream(bis);
dos.writeUTF(CONNECT);
dos.flush();
String response = dis.readUTF();
log.debug("got server message: " + response);
if (response.equals(CONNECTED)) {
return true;
}
} catch (Exception e) {
log.error("an error occured", e);
}
return false;
}
示例7: init
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
public void init() {
if (initialized)
return;
invitesWindow = new InvitesWindow();
playersWindow = new InvitesWindow();
initialized = true;
try {
socket = Gdx.net.newClientSocket(Net.Protocol.TCP, "localhost", 1337, new SocketHints());
} catch (Exception e) {
return;
}
new Thread(new Runnable() {
@Override public void run() {
final BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while (true) {
try {
final String msg = r.readLine();
Gdx.app.postRunnable(new Runnable() {
@Override public void run() {
ClientServerMessage message = ClientServerMessage.json.fromJson(ClientServerMessage.class, msg);
receive(message);
}
});
} catch (IOException ignored) {
System.out.println(ignored.getMessage());
}
}
}
}).start();
sendToServer(ClientServerMessage.Type.loadPlayersToInvite);
sendToServer(ClientServerMessage.Type.loadInvites);
}
示例8: accept
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
@Override
public Socket accept (SocketHints hints) {
try {
return new NetJavaSocketImpl(server.accept(), hints);
} catch (Exception e) {
throw new GdxRuntimeException("Error accepting socket.", e);
}
}
示例9: accept
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
@Override
public Socket accept(SocketHints hints) {
try {
return new ClientSocket(server.accept(), hints);
} catch (Exception e) {
throw new GdxRuntimeException("Error accepting socket.", e);
}
}
示例10: newClientSocket
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
public Socket newClientSocket(Protocol protocol, String host, int port, SocketHints hints) {
return nativeNet.newClientSocket(protocol, host, port, hints);
}
示例11: newClientSocket
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
return new NetJavaSocketImpl(protocol, host, port, hints);
}
示例12: newClientSocket
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
@Override
public Socket newClientSocket(final Protocol protocol, final String host, final int port, final SocketHints hints) {
return net.newClientSocket(protocol, host, port, hints);
}
示例13: newClientSocket
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
throw new UnsupportedOperationException("Not implemented");
}
示例14: newClientSocket
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
@Override
public Socket newClientSocket (Protocol protocol, String host, int port, SocketHints hints) {
return new NetJavaSocketImpl(protocol, host, port, hints);
}
示例15: newClientSocket
import com.badlogic.gdx.net.SocketHints; //导入依赖的package包/类
@Override
public Socket newClientSocket(Protocol protocol, String host, int port, SocketHints hints) {
return new ClientSocket(protocol, host, port, hints);
}