Created
April 6, 2017 21:14
-
-
Save terry182/f27eebb947c5451f0116dce98c5411a0 to your computer and use it in GitHub Desktop.
電網導P2 Server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.*; | |
| import java.net.*; | |
| class P2Server | |
| { public static void main(String args[]) throws Exception | |
| { DatagramSocket serverSocket = new DatagramSocket(9090); | |
| // System.out.println("Server now running on 9090..."); | |
| while (true) | |
| { DatagramPacket receivedPacket = new DatagramPacket(new byte[128], 128); | |
| serverSocket.receive(receivedPacket); | |
| String sentence = new String(receivedPacket.getData()); | |
| InetAddress ipAddress = receivedPacket.getAddress(); | |
| int port = receivedPacket.getPort(); | |
| System.out.println("Receive from " + ipAddress + ":" + port + " : " + sentence); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment