Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.udp;
- import java.io.IOException;
- import java.net.*;
- public class Server{
- private DatagramSocket socket;
- private byte[] buf = new byte[256];
- public static void main(String[] args) throws IOException{
- if(args.length != 1) {
- System.out.println("Error calling method");
- return;
- }
- new Server().run(Integer.parseInt(args[0]));
- }
- public void run(int port) throws IOException {
- boolean running = true;
- socket = new DatagramSocket(port);
- while(running) {
- DatagramPacket packet = new DatagramPacket(buf, 256);
- socket.receive(packet);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement