Datagram Socket Problem !!!!!!!!!!!!!!!

Hi to All ,
I am facing problem regarding the Datagram Socket Programming .
I wana to make a java program that is using the datagram socket. I wana to retrive the IP Address of all the machines that are connected in a local network by using the datagram Socket !!!!!!!!!!!!!!
As i am new in java Socket Programming , Can any body help me How am i sends a Broadcast Packet to all the machines that are connected in a local network , so that i retrieve the IP Address of all the machines that are presented in a local network
Please give the Solution

You can't use any Java to find all the machines on your network (whatever that means). You will need to shell out and parse the output from the shell.
If you want to simply use datagram sockets to send UDP broadcasts, the Javadoc covers it in some detail.
However, UDP is called a "send and pray" protocol - you send the message and pray that the client receives it. Also, there is no acknowledgement from the client when the message is received. So, in a nutshell, you cannot use multicasts to find clients.
You need to use some other protocols in the TCP/IP stack for finding machines on the network - and Java does not have any pre-built support for these.

Similar Messages

  • Datagram Sockets

    Hi Folks. I am curently devising an presence service andinstant messaging system on UNIX. The problem is I am looking to open a datagram socket connection with a client on another computer on port 1115. Hhow am I able to send them a message without them having to run any program on their system. How can I just send the message to them, like a proper instant messaging system.
    PS How do i get them to listen on port 1115, without them having to do anything. How can I open a server connection on port 1115 for them
    Any help is appreciated
    Ewan

    When you "proper instant messaging system" I assume you mean something like talk or ytalk rather than ICQ or YahooIM. The former have daemons that run listening for messages which are started by the system.
    the user (or administrator) of the machine is going to have to explicitly open a socket to listen for connections on the port, by running a program or by having a daemon start at boot.

  • Urgent Datagram Socket

    hi to All,
    I am facing some problem when i am broadcasting a data packet by using the datagram socket in java
    I am using the IP Address 255.255.255.255 to broadcast a packet . The Packet is send , but the programs goes in Indefinite till when receiving a Message from the Machines that are connected in the Local Network !!!!!!!!!!!
    Actually , i wana to collect all the Machines IP Address by sending a Broadcast Packet(by using UDP) . Can i body tell whts the Solution of this probelm , so that i retrieve the IP Address of the Machines that are connected in a local Network

    " You can only do it if you know that all machines will respond to an udp package on some port."
    HI
    I am having trouble in broadcasting the data on 255.255.255.255 at port 3988.
    Can you people send me the code for -
    How to broadcast the data on 255.255.255.255 at port 3988 ??
    and
    How it can be received by any client machine at its port 3988 and How client can come to know from where the data is coming i.e. from which machine the data is coming.
    As you have told that it is possible if we know the port "You can only do it if you know that all machines will respond to an udp package on some port.", the port is 3988.
    Thanks & Regards
    Abhishek

  • Datagram socket and security manager

    I have subclassed the security manager to implement my own network security rules.
    However when the receive(datagramPacket) method is called by the my datagram socket, the host parameter passed to the checkAccept(host, port) method does not belong to the sender of the packet(to be received).
    How then can malicious addresses be blocked by the security manager, as suggested by the comments in the source code of DatagramSocket.
    Any help is greatly appreciated. Thank you in advance.

    However when the receive(datagramPacket) method is
    called by the my datagram socket, the host parameter
    passed to the checkAccept(host, port) method does
    not belong to the sender of the packet(to be
    received).It should. What are you getting instead?

  • Datagram Socket  send different sizes Buffers ...

    hi,
    I'm sending different sizes Datagrams from a datagram socket
    so how can I receive them
    I've tried to send the packet in two packets the first one is fixed size that carries the size of the real data then create a suitable buffer on the client side to receive the second packet but the result is very slow ...
    I'd like to know any suggestions about how to do this properly
    to reach a stream like synchronization between the client and the server ..
    thanks in advance

    use a receive buffer large enough for the largest package possible on your network. Typically, this is 1500 data bytes, but it depends on the network technology. If you want to be sure, allocate a 65536 bytes buffer, which will fit for any technology. But typically, 1550 will fit in a LAN.

  • Datagram socket is not working

    Hi,
    I made a datagram socket and try to send a byte array. but when I called socket.send method it returned an error that an operation is attempted on invalid socket. What I am missing
    here is my code...
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="480" height="262">
    <mx:Script><![CDATA[
    private var udp:DatagramSocket = new DatagramSocket();
    private var address:String = "255.255.255.255";
    private var port:uint = 200;
    private function OnSend():void
      udp.addEventListener(DatagramSocketDataEvent.DATA, RecvUdpDataHandler);
      var byteArray:ByteArray = new ByteArray();
      byteArray.endian = Endian.LITTLE_ENDIAN;
      byteArray.writeMultiByte("dvcrNetshare", "US-ASCII");
      byteArray.writeUnsignedInt(123);
      udp.send(byteArray, 0, byteArray.length, address, port);
      udp.receive();
    private function RecvUdpDataHandler(obj:DatagramSocketDataEvent):void
      var str:String = obj.srcAddress;
      var srcport:int = obj.srcPort;
    ]]></mx:Script>
    <mx:Button x="206" y="134" label="Send" click="OnSend()"/>
    </mx:WindowedApplication>
    Thanks

    You can call Apple and appeal their decision if you wish to (or go back to the store and ask for a supervisor or manager to assess your device - basically dispute the genius claim and ask to have it bumped up the chain of command).  Ultimately though they are the ones who decide if your damage is a warranty-related defect or something caused by accidenatal damage or abuse.  If they say you are not eligible for a warranty repair, then you pay the fee for an out of warranty repair.

  • Datagram socket

    Can I have a datagram socket server receive messages from a stream socket client. Thanks,

    No, and you are in the wrong forum. Moving this to the Networking forum.

  • Can u tell how to send the pictures using datagrams sockets in java

    hi to all, i am making chat application , i am datagrams socket(packets) for sending and receiving messages . datagrams only send and receive messages in bytes . can u tell me how to send the picture to other person using datagrams.
    Thankyou.

    look her
    http://forum.java.sun.com/thread.jsp?forum=31&thread=330989&tstart=0&trange=15
    and look up Serialisation

  • Help: Send and Receive through Datagram Socket

    I am trying to create a client/server using Datagram Socket (UDP) as communication. I have a Recive and a Send class that implements runnable and are responsible for receiving and sending of message. I have two other classes Server and Client that are utilizing these. Now i can get the receive and send to work fine, but i am having trouble retrieving the message from the receive thread that i created in each of server/client. I've tried inserting a method so the server/client can call on to get the message (Receive.Get_Message()) but unfortunately this isn't working as i wanted. Since my server and clients are not implemented as runnables, i can only issue the command in some serialize fashion. What i really want to do is that whenever the message is receive by the Receive thread, it will immediately be send back to server/client and display right then, independent of what i was doing. (i have a command interface for S/C so it just sits there to wait for command, now what i would like is to have the S/C display the message it gets immediately after it gets it even when it's waiting for user input. since my program is waiting for a command, i really could not use the method describe above to achieve this) Could anyone help me with this?
    Thanks!
    Hung-Hsun Su

    u cant use the observer pattern. or at least i can't figure out how to implement it with sockets.
    you should use threading.
    public void run()
      while(true)
         //keep reading from socket
         InStream output = socket.getInputStream();
         InputStreamReader ir = new InputStreamReader(output)
         BufferedReader reader = new BufferedReader(ir);
         String s = null;
         while(s == null)
           s = reader.readLine();
         //then do whatever you want to the received string "s"
    }

  • How to run a datagram socket client and server program

    hi,
    I am new to socket programming. I am following the tutorial of sun for socket programming...The link is
    http://java.sun.com/docs/books/tutorial/networking/datagrams/clientServer.html
    I have understood the concept, but the problem is i cannot run the program. I am using netbeans and i have created a package and stored the files QuoteServer,QuoteServerThread, QuoteClient in this package. How can i make the server program run first and then client program in netbeans
    kindly help me
    Thankyou

    I think you are trying to run both server and client
    on one machine!!!
    It is impossible, your server is blocking the port to
    send packets, so you must run client on another
    computer!!!It's not impossible to run a client and server on the same machine just for testing or as a demo. Just have the server listen on one port and the client use a different port.
    No need to use 2 seperate computers. I've done it one computer before without a problem.
    Nick

  • Data socket problems with LVRT 8.2

     I am in the process of migrating to LV 8.2 from LV7.1.1. My system has 18 RT targets which send data to a Host PC through data socket (DS). The Host PC runs LV on Windows XP Pro.  With LV7.1.1 on both host and RT targets DS works perfectly. The RT targets update the host every 500 ms.
    I've taken a three-step process in the migration. First tests were done with the host migrated to LV8.2 while keeping the RTs at LV7.1.1. Result: the system worked perfect. Then I changed one RT to 8.2 keeping the rest the rest at LV7.1.1. Result: DS timed out before all the data could be sent to Host. Finally, all RTs were migrated to LVRT 8.2. Result: Only about 5 out of the 18 RTs report to the Host before DS times out. However, if only one RT target is used, i.e., the other 17 RTs are diasbled, communication is very fast. Is there a special setting that I need to make? Btw, the roughly 5 RTs that report vary randomly from test to test, i.e., there is no bias towards any particular RTs.
    I am using the same source code developed under LV7.1.1, so the only changes made are the ones that take place when one opens LV7.1.1 code in LV8.2. Some VIs get converted in the process.
    Any ideas?
    Chatonda Mtika
    Algis Corp
    Vancouver, Canada

    Ben,
    I must say I am very surprised by Nadim's email. His point, which I must say I don't agree with, was made quite clear to me yesterday during a conference call between my team and the NI team comprising Chris, Nadim, and Avinash. So I don't know what purpose this morning's email is supposed to serve. Be that as it may, I think NI has gotten it wrong here. I do not think it should be one or the other. The discussion forum is a much wider forum comprised of people with varying experiences - not just NI employees. That is precisely why I posted my problem to the forum: to tap into the vast experiences of the discussants. But when I did not get any responses after I had posted answers to Nadim's questions, I decided to make a formal service request to NI, all perfectly legal. So I was really surprised when I was being blamed for tying up NI resources on one problem. I believe the resource allocation issue should be NI's to solve, not mine. I have no way of knowing that NI had formally assigned somebody to my problem. What if nobody from NI responds, am I allowed to make a service request to NI? My feeling is that NI's logic is flawed here, assuming Nadim's views are NI's views.
    Thanks,
    Chatonda Mtika
    Algis Corporation
    Vancouver, Canada

  • Sockets problem

    Hi ,
    I written a server class that simply writes the numbers and the client simply reads those numbers and prints them. When I run the both client and server on tha same machine there is no data loss found. But when I run the server on different machine than client I found heavy dataloss.(while theserver written numbers from 1-9000 the client is able read only 6000 plus). The data loss is increased when the data read from the server socket created by the VB application. Here with i am pasting the code snippet for the Server and the Client java files . Please help me in solving this problem.
    Client.java
    import java.net.*;
    import java.io.*;
    public class Client
         static Socket client = null;
         ObjectInputStream is = null;
         public Client() throws Exception
              client = new Socket("rajsekhar",3333);
              is = new ObjectInputStream (client.getInputStream());
              while(true){
                   Integer in = (Integer)is.readObject();
                   System.out.println(in.toString());
         public static void main(String[] args) throws Exception
              new Client();
    Server.java
    import java.net.*;
    import java.io.*;
    public class Server
         public static void main(String[] args) throws Exception
              ServerSocket server = null;
              server = new ServerSocket(3333);
              Socket s = server.accept();
              ObjectOutputStream os = new ObjectOutputStream(s.getOutputStream());
              int i =1;
              while(true)
                   os.writeObject(new Integer(i));
                   System.out.println(i);
                   i++;
    please help me .
    thanks in advance,
    Sridhar Reddy .R

    This has nothing to do with JSSE; please post in a more appropriate forum.

  • Serversock/socket problem pls Help

    Hi all,
    I have a serversocket that accepts client's connections, reads from this stream, processes the data and sends back response to the client. This works fine for a standard scenario.
    The problem occurs if for some reason the client looses connection after writing to the serversocket. The server behaves as if nothing happens and sends back the response. I want the server to be able to detection any connection loss and report back. My code snippet is shown below
    ServerSocket server;
    Socket conn;
    BufferedReader input;
    PrintWriter out;
    try{
    server= new ServerSocket(4550,10);
    conn=server.accept();
    input = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String data=input.readLine();
    process data .....
    out = new PrintWriter(conn.getOutputStream(), true);     
    out.println(processed_data);
    }catch(IOException e){
    e.printStackTrace();
    }finally{
    try{
    input.close();
    out.close();
         conn.close();
         }catch(Exception uncaught){}
    If during process data, the client looses connection, the program behaves as if the connection still exist. Any suggesion would be highly appreciated
    Regards
    Tim

    err, yeah, i got that bit....
    and there is nothing, nothing at all in java, C, C++, any and i mean ANY TCP/IP programming that can tell if the client has been unplugged without trying to send something to it
    you can use a keepAlive in Socket to automatically occasionally send a dummy packet (for which it expects a response)
    but apart from that the Socket cannot know it is not connected unless it recieves indication from the client (the end that is closed first sends a FIN packet and the other end replies with ACK FIN)
    a pair of Sockets connectd through a network does not get a permanent physical connection, they give the impression of such by exchanging packets with sequence numbers and ack numbers coresponding to the last packet recived.
    if neither Socket has nothing to send, nothing is sent and it is assumed that the connection is still valid, so isConnected() will return true unless it actually knows that the client has closed the connection or an Exception occured when it tried to send something
    isConnected() does not test the connection, just reports true if it has been connected and there has not been an IOException or either end has closed
    maybe you could explain why you need to avoid sending the response if the client has been unplugged?

  • Create OPC I/O server and front panel data socket problem

    Hi all!
    I installed the NI OPC server. When I try to create a new server I/O in a LabVIEW project I don't see the "OPC client" possibility.
    Is something software missing? 
    Other question: I tryed to connect to OPC server using front panel data socket but my problem is same. When I click the numeric control and I go to the "data operation" menu there is no possibility to make data socket connection. 
    I don't know what is the problem.
    I attached two pictures about my problem. 
    Solved!
    Go to Solution.

    Dear vajasgeri1,
    do you have LabVIEW DSC module installed? Without it you will not have the OPC client funtionality.
    And to configure DataSocket binding you need to go to the Data Binding tab in the Properties of a control.
    BR,
    Mateusz Stokłosa
    Applications Engineer
    National Instruments

  • Socket Problem, Problem about printing the response from server

    Or even I am not sure if there is a response from server. My code is like that
                   //Connection between, httpProxy and target adress
                   Socket clientSocket= new Socket("some host", 80);
                   DataOutputStream outToServer= new DataOutputStream(clientSocket.getOutputStream());
                   BufferedReader inFromServer= new BufferedReader(new     InputStreamReader(clientSocket.getInputStream()));
                   //The first way
                   //outToServer.writeBytes("GET http://www.somehost.com/ HTTP/1.1"+ '\n');
                   //System.out.println("FROM SERVER: "+inFromServer.readLine());
                   //The second way
                   PrintWriter out_writer = new PrintWriter(outToServer, false);
                   out_writer.println("GET http://www.somehost.com/ HTTP/1.1");
                   out_writer.println("Host: localhost:80");
                   out_writer.println("Connection: Close");
                   out_writer.println();
                                        //The second way cont.
                   String s = null;
                   while ((s = inFromServer.readLine()) != null)
                   System.out.println(s);
                   inFromServer.close();There are the two ways that I tried, and both of them didn't work. Why they are not working ? How can I solve it ?

    problem is solved, the reason it doesn't work is i didn't write the parts correctly. I mean it should be exactly the same packetIf you mean that the entire request must be sent in a single IP packet, this isn't true.
    and host name must also be exactly sent to server.Of course.
    They must be like in the wireshark.No. The actual data you send must be the same, but the server has no way of telling about what the IP packet looks like or how many there were.
    One of your problems is that newlines in HTTP are defined as \r\n. In one case you're just using \n and in the other case you're using whatever the platform line terminator is. Neither is correct.

Maybe you are looking for

  • Exception raised while trying to join Table and Stream

    I have written a sample Project to fetch the data from a Table and join it with the Input Stream. Followed the same procedure specified at http://download.oracle.com/docs/cd/E17904_01/doc.1111/e14301/processorcql.htm#CIHCCADG I am getting the excepti

  • Safari 3.2.1 crash

    I have Safari 3.2.1 and it crashes since the latest update. The maximum amount of time it has stayed open is 3 minutes. Please help. I have repaired permissions, trashed the Safari plist, cleared Safari cache, tried to get rid of duplicate fonts, exc

  • Resizing problems

    I am trying to make an action for saving images for web at a size of 800x800. When I am making the action I resize the image, but instead of resizing by pixels, it resizes by ratio, for example 29% from the image. So, when I use the action it uses re

  • I Need to Return Two values or more from Function, Is this possible?

    Below is the offending query, I am trying to pass v_bu and v_po to this function, and after validations then return v_count and v_action is this possible in a function? I am having problem returning two values. see below code function po_edi_func(v_b

  • Setting the position of the mouse pointer

    Hi, I want to explicitly set the mouse pointer to an definded location, e.g. when a window is opened. Is there a method I can invoke or a work around to set the mouse pointer to, say, posx = 100 and posy = 150? Are there any other manipulating method