Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test1;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.net.InetAddress;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Vallentin <[email protected]>
- * @since April 8, 2012
- *
- */
- public class Client
- {
- public static Socket socket;
- public static int port = 2406;
- public static String ip = "";
- public static void main(String[] args)
- {
- try
- {
- String local;
- try
- {
- local = InetAddress.getLocalHost().getHostAddress() + ":" + port;
- }
- catch (UnknownHostException ex)
- {
- local = "Network Error";
- }
- ip = (String) JOptionPane.showInputDialog(null, "IP: ", "Info", JOptionPane.INFORMATION_MESSAGE, null, null, local);
- port = Integer.parseInt(ip.substring(ip.indexOf(":") + 1));
- ip = ip.substring(0, ip.indexOf(":"));
- socket = new Socket(ip, port);
- String username = System.getProperty("user.name");
- username = (String) JOptionPane.showInputDialog(null, "Username: ", "Info", JOptionPane.INFORMATION_MESSAGE, null, null, username);
- ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
- oos.writeObject(username);
- ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
- String response = (String) ois.readObject();
- JOptionPane.showMessageDialog(null, response, "Message", JOptionPane.INFORMATION_MESSAGE);
- }
- catch (Exception ex)
- {
- JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage(), "Alert", JOptionPane.ERROR_MESSAGE);
- System.exit(0);
- }
- }
- }
- package test1;
- import java.io.Serializable;
- /**
- *
- * @author Vallentin <[email protected]>
- * @since April 8, 2012
- *
- */
- public class DataPackage implements Serializable
- {
- public float x = 0.0f;
- public float y = 0.0f;
- public String username = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement