Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //UDPServidor.java, Willian Luigi (c) CODE.ME
- //http://codeme.forumeiros.com/t44-conexao-udpservidor-cliente#256
- import java.io.*;
- import java.net.*;
- class UDPServidor {
- public static void main(String[] args) throws Exception {
- DatagramSocket entry = new DatagramSocket(7777);
- byte[]
- recebido = new byte[1024],
- enviado = new byte[1024];
- while (true) {
- DatagramPacket pacotesRecebidos = new DatagramPacket(recebido, recebido.length);
- entry.receive(pacotesRecebidos);
- String msg = new String(pacotesRecebidos.getData());
- InetAddress ip = pacotesRecebidos.getAddress();
- int port = pacotesRecebidos.getPort();
- String msg_alt = msg.toUpperCase();
- enviado = msg_alt.getBytes();
- DatagramPacket pacotesEnviados = new DatagramPacket(enviado, enviado.length, ip, port);
- entry.send(pacotesEnviados);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment