Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.Socket;
- import java.net.InetAddress;
- import java.net.InetSocketAddress;
- import java.net.UnknownHostException;
- import java.util.*;
- import java.io.*;
- public class EsSocket1 {
- public static void main(String clinet[]){
- try{
- byte[] addr = InetAddress.getByName("0.0.0.0").getAddress();//"172.22.111.26"
- InetAddress ia; //ip address del client
- InetSocketAddress isa;
- Socket sClient = new Socket();
- ia = InetAddress.getByAddress(addr);
- isa = new InetSocketAddress(ia, 45841);
- sClient.connect(isa);
- System.out.println("Porta allocata: " + sClient.getLocalPort());
- System.out.println("inserisci una stringa");
- InputStreamReader tastiera=new InputStreamReader(System.in);
- BufferedReader br= new BufferedReader(tastiera);
- String frase=br.readLine();
- OutputStream toSrv= sClient.getOutputStream();
- toSrv.write(frase.getBytes(),0,frase.length());
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement