Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import java.net.Socket;
  2. import java.net.InetAddress;
  3. import java.net.InetSocketAddress;
  4. import java.net.UnknownHostException;
  5. import java.util.*;
  6. import java.io.*;
  7.  
  8. public class EsSocket1 {
  9. public static void main(String clinet[]){
  10. try{
  11. byte[] addr = InetAddress.getByName("0.0.0.0").getAddress();//"172.22.111.26"
  12. InetAddress ia; //ip address del client
  13. InetSocketAddress isa;
  14. Socket sClient = new Socket();
  15. ia = InetAddress.getByAddress(addr);
  16. isa = new InetSocketAddress(ia, 45841);
  17. sClient.connect(isa);
  18. System.out.println("Porta allocata: " + sClient.getLocalPort());
  19. System.out.println("inserisci una stringa");
  20. InputStreamReader tastiera=new InputStreamReader(System.in);
  21. BufferedReader br= new BufferedReader(tastiera);
  22. String frase=br.readLine();
  23. OutputStream toSrv= sClient.getOutputStream();
  24. toSrv.write(frase.getBytes(),0,frase.length());
  25. }catch(Exception e){
  26. e.printStackTrace();
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement