Advertisement
Sowa107

Klient UDP

Nov 18th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package udp;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.awt.image.DataBufferByte;
  5. import java.awt.image.WritableRaster;
  6. import java.io.*;
  7. import java.net.*;
  8. import java.nio.file.Files;
  9. import java.nio.file.Path;
  10. import java.nio.file.Paths;
  11.  
  12. import javax.imageio.ImageIO;
  13.  
  14. public class Klient {
  15.  
  16.     public static void main(String args[]) throws Exception {
  17.  
  18.         //BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
  19.         DatagramSocket clientSocket = new DatagramSocket();
  20.         InetAddress IPAddress = InetAddress.getByName("localhost");
  21.         byte[] sendData = new byte[50960];
  22.         byte[] receiveData = new byte[1024];
  23.         Path imgPath = Paths.get("C:\\Users\\s12616\\Documents\\pepe.jpg");
  24.        
  25.         sendData = Files.readAllBytes(imgPath);
  26.         DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
  27.         clientSocket.send(sendPacket);
  28.         DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
  29.         clientSocket.receive(receivePacket);
  30.         String modifiedSentence = new String(receivePacket.getData());
  31.         System.out.println("FROM SERVER:" + modifiedSentence);
  32.         clientSocket.close();
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement