Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sockets;
- import java.net.Socket;
- public class Sockets {
- public static void main(String[] args) {
- Sockets bar = new Sockets();
- }
- public Sockets() {
- // Start a new thread (mind you this is ugly test code, you should
- // create a seperate class that implements the runnable interface.
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- System.out.println("trying to create socket");
- // Adjust this to connect to your server's IP/port.
- Socket socket = new Socket("127.0.0.1", 8181);
- System.out.println("socket created");
- } catch (Exception ex) {
- System.out.println(ex);
- }
- }
- });
- try {
- // Start the thread, basically this calls the thread's run method
- // asynchronously.
- thread.start();
- // This will cause the main thread to wait until the other
- // thread is completed.
- thread.join();
- } catch (Exception ex) {
- System.out.println(ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment