本文整理汇总了Java中java.net.SocketException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java SocketException.printStackTrace方法的具体用法?Java SocketException.printStackTrace怎么用?Java SocketException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.SocketException
的用法示例。
在下文中一共展示了SocketException.printStackTrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocalIpAddress
import java.net.SocketException; //导入方法依赖的package包/类
/**
* Get local IP address
*
* @return ip address
*/
static String getLocalIpAddress() {
String ip = "127.0.0.1";
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()
&& !inetAddress.isLinkLocalAddress()) {
ip = inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return ip;
}
示例2: getIpAddress
import java.net.SocketException; //导入方法依赖的package包/类
private String getIpAddress() {
String ip = "";
try {
Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
while (enumNetworkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = enumNetworkInterfaces.nextElement();
Enumeration<InetAddress> enumInetAddress = networkInterface.getInetAddresses();
while (enumInetAddress.hasMoreElements()) {
InetAddress inetAddress = enumInetAddress.nextElement();
if (inetAddress.isSiteLocalAddress()) {
ip += inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
ip += "Something Wrong! " + e.toString() + "\n";
}
return ip;
}
示例3: getLocalIpAddress
import java.net.SocketException; //导入方法依赖的package包/类
private String getLocalIpAddress() {
String ipAddrrss = "";
try {
Enumeration<NetworkInterface> enumNetworkInterfaces = NetworkInterface.getNetworkInterfaces();
while (enumNetworkInterfaces.hasMoreElements()) {
Enumeration<InetAddress> enumInetAddress = enumNetworkInterfaces.nextElement().getInetAddresses();
while (enumInetAddress.hasMoreElements()) {
InetAddress inetAddress = enumInetAddress.nextElement();
if (inetAddress.isSiteLocalAddress()) {
ipAddrrss = ipAddrrss + inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return ipAddrrss;
}
示例4: getLocalIpAddress
import java.net.SocketException; //导入方法依赖的package包/类
/**
* 获取本机IP函数
*/
public static String getLocalIpAddress() {
try {
String ipv4;
ArrayList<NetworkInterface> mylist = Collections.list(NetworkInterface
.getNetworkInterfaces());
for (NetworkInterface ni : mylist) {
ArrayList<InetAddress> iaList = Collections.list(ni.getInetAddresses());
for (InetAddress address : iaList) {
if (!address.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ipv4 =
address.getHostAddress())) {
return ipv4;
}
}
}
} catch (SocketException ex) {
ex.printStackTrace();
}
return "0";
}
示例5: main
import java.net.SocketException; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// reserve the security properties
String reservedSFacProvider =
Security.getProperty("ssl.SocketFactory.provider");
// use a non-existing provider so that the DefaultSSLSocketFactory
// will be used, and then test against it.
Security.setProperty("ssl.SocketFactory.provider", "foo.NonExistant");
SSLSocketFactory fac = (SSLSocketFactory)SSLSocketFactory.getDefault();
try {
fac.createSocket();
} catch(SocketException se) {
// if exception caught, then it's ok
System.out.println("Throw SocketException");
se.printStackTrace();
return;
} finally {
// restore the security properties
if (reservedSFacProvider == null) {
reservedSFacProvider = "";
}
Security.setProperty("ssl.SocketFactory.provider",
reservedSFacProvider);
}
// if not caught, or other exception caught, then it's error
throw new Exception("should throw SocketException");
}
示例6: clientThread
import java.net.SocketException; //导入方法依赖的package包/类
public clientThread(Socket clientSocket, clientThread[] threads, MultiThreadChatServerSync mtcss) {
this.clientSocket = clientSocket;
this.mtcss = mtcss;
if (config == null) {
Yaml yaml = new Yaml();
InputStream in = ClassLoader.getSystemResourceAsStream("config.yml");
config = yaml.loadAs(in, ConfigConfiguration.class);
}
try {
this.clientSocket.setSoTimeout(config.getMaxTimeOut() * 1000);
} catch (SocketException e) {
e.printStackTrace();
}
service = new ToneAnalyzer("2017-09-21", config.getWatsonUser(), config.getWatsonPass());
}
示例7: Server
import java.net.SocketException; //导入方法依赖的package包/类
public Server()
{
super("Server");
displayArea = new JTextArea(); // create displayArea
add(new JScrollPane(displayArea), BorderLayout.CENTER);
setSize(400, 300); // set size of window
setVisible(true); // show window
try // create DatagramSocket for sending and receiving packets
{
socket = new DatagramSocket(5000);
}
catch (SocketException socketException)
{
socketException.printStackTrace();
System.exit(1);
}
}
示例8: getIpAddress
import java.net.SocketException; //导入方法依赖的package包/类
/**
* 获取本机IP地址
*
* @return null:没有网络连接
*/
public static String getIpAddress() {
try {
NetworkInterface nerworkInterface;
InetAddress inetAddress;
for (Enumeration<NetworkInterface> en
= NetworkInterface.getNetworkInterfaces();
en.hasMoreElements(); ) {
nerworkInterface = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr
= nerworkInterface.getInetAddresses();
enumIpAddr.hasMoreElements(); ) {
inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
return null;
} catch (SocketException ex) {
ex.printStackTrace();
return null;
}
}
示例9: updateIpAddress
import java.net.SocketException; //导入方法依赖的package包/类
private void updateIpAddress() {
try {
Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces();
ipAddress = null;
while( b.hasMoreElements()){
NetworkInterface iface = b.nextElement();
if (iface.getName().startsWith("dock")) {
continue;
}
for ( InterfaceAddress f : iface.getInterfaceAddresses()) {
if (f.getAddress().isSiteLocalAddress()) {
ipAddress = f.getAddress().getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
}
示例10: handleSetupRequest
import java.net.SocketException; //导入方法依赖的package包/类
@Override
void handleSetupRequest(RtspRequest r) {
// Get the stream that this request is referring to
String control = r.getUri().getLastPathSegment();
RtpMedia rtpMedia = rtspServer.getRtpMediaFromControl(control);
try {
// TODO: Determine protocol: UDP/TCP
TransportHeader t = TransportHeader.fromString(r.getTransport());
RtpStream stream = initializeRtpStream(t.rtpProtocol, rtpMedia, t);
configureRtpStream(stream, Utils.getNewSsrc(), t, socket.getInetAddress());
RtspResponse res = RtspResponse.buildSetupResponse(r, stream);
eventBus.post(new RtspSessionEvent.SendResponse(r, res));
} catch (SocketException e) {
// TODO: Handle exception
e.printStackTrace();
}
}
示例11: Acceptor
import java.net.SocketException; //导入方法依赖的package包/类
public Acceptor(ServerSocket serverSocket, URI uri) {
socket = serverSocket;
target = uri;
pause.set(new CountDownLatch(0));
try {
socket.setSoTimeout(ACCEPT_TIMEOUT_MILLIS);
} catch (SocketException e) {
e.printStackTrace();
}
}
示例12: getIPAddress
import java.net.SocketException; //导入方法依赖的package包/类
/**
* 获取IP地址
* <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
*
* @param useIPv4 是否用IPv4
* @return IP地址
*/
public static String getIPAddress(final boolean useIPv4) {
try {
for (Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); nis.hasMoreElements(); ) {
NetworkInterface ni = nis.nextElement();
// 防止小米手机返回10.0.2.15
if (!ni.isUp()) continue;
for (Enumeration<InetAddress> addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) {
InetAddress inetAddress = addresses.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String hostAddress = inetAddress.getHostAddress();
boolean isIPv4 = hostAddress.indexOf(':') < 0;
if (useIPv4) {
if (isIPv4) return hostAddress;
} else {
if (!isIPv4) {
int index = hostAddress.indexOf('%');
return index < 0 ? hostAddress.toUpperCase() : hostAddress.substring(0, index).toUpperCase();
}
}
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return null;
}
示例13: getIPAddress
import java.net.SocketException; //导入方法依赖的package包/类
/**
* 获取IP地址
* <p>需添加权限 {@code <uses-permission android:name="android.permission.INTERNET"/>}</p>
*
* @param useIPv4 是否用IPv4
* @return IP地址
*/
public static String getIPAddress(boolean useIPv4) {
try {
for (Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); nis.hasMoreElements(); ) {
NetworkInterface ni = nis.nextElement();
// 防止小米手机返回10.0.2.15
if (!ni.isUp()) continue;
for (Enumeration<InetAddress> addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) {
InetAddress inetAddress = addresses.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String hostAddress = inetAddress.getHostAddress();
boolean isIPv4 = hostAddress.indexOf(':') < 0;
if (useIPv4) {
if (isIPv4) return hostAddress;
} else {
if (!isIPv4) {
int index = hostAddress.indexOf('%');
return index < 0 ? hostAddress.toUpperCase() : hostAddress.substring(0, index).toUpperCase();
}
}
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return null;
}
示例14: establishConnection
import java.net.SocketException; //导入方法依赖的package包/类
@Override
protected void establishConnection(InetAddress addr) {
try {
socket = new DatagramSocket(mHostPort);
mLog.debug("Established local socket at ", mHostPort, " with a destination of ", addr, ":", mDestPort);
update(mStatus.connectionEstablished());
} catch (SocketException e) {
e.printStackTrace();
}
startSendThread(addr);
}
示例15: UDPServer
import java.net.SocketException; //导入方法依赖的package包/类
public UDPServer() {
try {
datagramSocket = new DatagramSocket(8088);
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}