The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

hiiiiiiiiiiiii

Posted by fahad on October 16, 2001 at 11:24 AM

> i can not correct the error in my program
> thanks ofr u help

> import java.net.*;
> import java.io.*;
> import java.util.*;

> public class ChatterServer {
> static final int INPORT = 1711;
> private byte[] buf = new byte[1000];
> private DatagramPacket dp =
> new DatagramPacket(buf, buf.length);
> // Can listen & send on the same socket:
> private DatagramSocket socket;

> }

> public ChatterServer() {
> try {
> socket = new DatagramSocket(INPORT);
> System.out.println("Server started");
> while(true) {
> // Block until a datagram appears:
> socket.receive(dp);
> String rcvd = Dgram.toString(dp) +
> ", from address: " + dp.getAddress() +
> ", port: " + dp.getPort();
> System.out.println(rcvd);
> String echoString =
> "Echoed: " + rcvd;
> // Extract the address and port from the
> // received datagram to find out where to
> // send it back:
> DatagramPacket echo =
> Dgram.toDatagram(echoString,
> dp.getAddress(), dp.getPort());
> socket.send(echo);
> }
> } catch(SocketException e) {
> System.err.println("Can't open socket");
> System.exit(1);
> } catch(IOException e) {
> System.err.println("Communication error");
> e.printStackTrace();
> }
> }

> public static void main(String[] args) {
> new ChatterServer();
> }






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us