当前位置: 首页>>代码示例>>Java>>正文


Java SocketException.printStackTrace方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:PrefStore.java

示例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;
}
 
开发者ID:yuvaraj119,项目名称:WifiChatSharing,代码行数:24,代码来源:MessageActivity.java

示例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;
}
 
开发者ID:kevalpatel2106,项目名称:remote-storage-android-things,代码行数:19,代码来源:FTPManager.java

示例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";
}
 
开发者ID:jonyChina162,项目名称:okhttpNDS,代码行数:23,代码来源:NetworkManager.java

示例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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:Fix5070632.java

示例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());
   
 }
 
开发者ID:Miic,项目名称:WholesomeChat,代码行数:18,代码来源:clientThread.java

示例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);
   } 
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:20,代码来源:Server.java

示例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;
    }
}
 
开发者ID:liying2008,项目名称:Simpler,代码行数:29,代码来源:NetWorkUtils.java

示例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();
    }
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:20,代码来源:RegistrationManager.java

示例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();
    }
}
 
开发者ID:devinbrown7,项目名称:streaminglib,代码行数:19,代码来源:RtspServerSession.java

示例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();
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:11,代码来源:SocketProxy.java

示例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;
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:35,代码来源:NetworkUtils.java

示例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;
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:35,代码来源:NetworkUtils.java

示例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);
}
 
开发者ID:flybotix,项目名称:highfrequencyrobots,代码行数:12,代码来源:UDPSender.java

示例15: UDPServer

import java.net.SocketException; //导入方法依赖的package包/类
public UDPServer() {
	try {
		datagramSocket = new DatagramSocket(8088);
	} catch (SocketException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:followwwind,项目名称:javase,代码行数:9,代码来源:UDPServer.java


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