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.

Similar Messages

  • 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 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.

  • 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.

  • 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

  • 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"
    }

  • Sending a File Using DataGram Sockets

    I writting one java program that can be used to transfer a file from one computer to another computer.
    I wrote using Sockets.
    But i want to do that using DatagramSockets. Can we send a file using DataGramSockets?
    Please reply soon.

    You can use DataGram but it is harder.
    One issue is you need to retransmit missing packets. This means you need to keep track of which packets have been sent and be able to send missing ones again.
    If Socket work for you why do you want to use DataGrams

  • 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

  • Datagram Sockets possible without locally available IP addresses?

    Hi everybody,
    before starting to dig into socket programming for the next few months, I'd like to get some facts clear that don't clarify to me by consuming the developer handbooks.
    I would like to send datagram packets out on all interfaces without bound sockets, i.e. I want to start something similar to a DHCP broadcast. Is this possible with Java? AFAIK always sockets are required , even for datagram communication.
    Thank you

    Hi! Thanks for you replies.
    I'm trying to create some kind of alternative host configuration protocol with a reference implementation. Since the server software will run on Java for various purposes, it would be fine if also the client software could be implemented in Java. Therefore, I'd need the possibility to send out datagrams on unconfigured network interfaces.
    As far as I have understood the DatagramSocketAPI, there's always the need to have a local socket available (IP address + port number) to actually send data - is that true?
    Thank you!

  • Acquiring local address for datagram socket created by DatagramChannel.open

    I've found that when I open an anonymous DatagramChannel (i.e. unbound, unconnected), the socket that it creates has no local address info I.e. no local port. Hopefully the example below will explain the problem...
    import java.nio.channels.DatagramChannel;
    import java.io.IOException;
    import java.net.DatagramSocket;
    import java.net.DatagramPacket;
    import java.net.InetAddress;
    public class QuickTest {
        public static void main( String[] args )    {
            try {
                DatagramChannel dc = DatagramChannel.open();
                DatagramSocket ds = dc.socket();
                byte[] ba = new byte[]{0,1,2,3};
                DatagramPacket dp = new DatagramPacket(ba,4,InetAddress.getLocalHost(),8000);
                ds.send(dp);
                System.out.println( "DatagramSocket from DatagramChannel");
                System.out.println();
                System.out.println( "          getInetAddress(): " + ds.getInetAddress());
                System.out.println( "         getLocalAddress(): " + ds.getLocalAddress ());
                System.out.println( "            getLocalPort(): " + ds.getLocalPort());
                System.out.println( "   getLocalSocketAddress(): " + ds.getLocalSocketAddress());
                System.out.println( "                 getPort(): " + ds.getPort());
                System.out.println( "  getRemoteSocketAddress(): " + ds.getRemoteSocketAddress());
                ds = new DatagramSocket();
                System.out.println();
                System.out.println();
                System.out.println();
                System.out.println( "DatagramSocket from new DatagramSocket()");
                System.out.println();
                System.out.println( "          getInetAddress(): " + ds.getInetAddress());
                System.out.println( "         getLocalAddress(): " + ds.getLocalAddress ());
                System.out.println( "            getLocalPort(): " + ds.getLocalPort());
                System.out.println( "   getLocalSocketAddress(): "    + ds.getLocalSocketAddress());
                System.out.println( "                 getPort(): " + ds.getPort());
                System.out.println( "  getRemoteSocketAddress(): " + ds.getRemoteSocketAddress());
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    }Running this program yields the following information....
    DatagramSocket from DatagramChannel
    getInetAddress(): null
    getLocalAddress(): 0.0.0.0/0.0.0.0
    getLocalPort(): 0
    getLocalSocketAddress(): 0.0.0.0/0.0.0.0:0
    getPort(): -1
    getRemoteSocketAddress(): null
    DatagramSocket from new DatagramSocket()
    getInetAddress(): null
    getLocalAddress(): 0.0.0.0/0.0.0.0
    getLocalPort(): 1194
    getLocalSocketAddress(): 0.0.0.0/0.0.0.0:1194
    getPort(): -1
    getRemoteSocketAddress(): null
    I understand that the sockets address will be included in any packets sent, but why can I determine the port for one and not the other? I would like to continue using an anonymous channel, but I also would like to have the port for use in my test harness and for logging info...
    Any info and possible work around for this behavior would be much appreciated.
    tx in advance.

    This looks like a bug in the socket returned by DatagramSocketChannel and you should report it.
    In the meantime you could either just use DatagramSocket, or if you must have NIO you could try binding this socket to null or new InetSocketAddress(null,0) and see whether getLocalPort() now returns the right data.

  • Datagram socket reads its own output?

    If I use a DatagramSocket to broadcast UDP packets, and also use the same DatagramSocket to try and read broadcasts from other hosts, it looks like I also end up reading back in all the packets that I broadcasted which creates a really messy situation.
    The only way I've found around this is to check the host address on every packet that comes in the door. This seems a little processor intensive if you're dealing with a lot of UDP traffic.
    Is there a better way around checking every packet? Being new to DatagramSocket, it seems odd to me that I use the same socket for reading and writing (hopefully it is threadsafe) but it is my understanding that I am using it correctly.

    OK, I guess that explains it. Since I'm dealing with
    DIS packets (Distributed Interactive Simulation),
    everything needs to be port 3000 because that is what
    all the systems talk.
    On multi-homed boxes I think I'll have to compare the
    packet's host address against each host address on
    the box. I guess I'll just tryt and do it in the
    most efficient manner possible... i.e. NOT a
    string.equals()And then what?
    What if the client is running on the same box as the server?

  • Datagram Socket & Datagram Channel performance

    Hi,<br>
    <br>
    I have been writing a video streaming server, and i have found that it does not perform anywhere near how it should (with available disk and network bandwidth). I have split the program down, and discovered that sending UDP packets appears to be running really slowly. Here is an example of the code i am using (sending blank packets for speed).<br>
    <br>
    <code>
    while (totalBytesSent < 150000000)<br>
    {<br>
    totalBytesSent += (188 * 7);<br>
    udpPacket.setData(payload);<br>
    udpPacket.setAddress(InetAddress.getByName("239.2.1.10"));<br>
    udpPacket.setPort(23232);<br>
    udpSocket.send(udpPacket);<br>
    }<br>
    </code>
    <br>
    it sends 150 megs of data in about 30 seconds = 5 meg/sec which is no where near the available bandwidth (gigabit lan).<br>
    <br>
    So, i thought maybe the NIO packages are the solution, but i get similar performance using the datagram channel and byte buffers with this code:<br>
    <br>
    <code>
    while (totalBytesSent < 160000000)<br>
    {<br>
    inStream.read(fileBuf);<br>
    buffer.put(fileBuf);<br>
    buffer.flip();<br>
    bytesSent += udpChannel.send(buffer, destAddress);<br>
    buffer.position(0);<br>
    totalBytesSent += (188*7);<br>
    }<br>
    </code>
    <br>
    what am i doing wrong? is there a better way of sending data over a network? what I am essentially doing is trying to read directly from a file on the disk and send it straight over the network as fast as possible. Any help much appreciated.<br>
    <br>
    Cheers<br>
    <br>
    Robert Clarkson<br>

    I don't know where your performance is going now, but you're in danger of not even sending all the data with this code.
    The canonical form of the NIO copying loop is:<br>
    <code><br>
    while (rdr.read(buffer) > 0 || buffer.position() > 0)<br>
    {<br>
    buffer.flip();<br>
    bytesSent += udpChannel.send(buffer,destAddress);<br>
    buffer.compact();<br>
    }<br>
    </code><br>
    Your version assumes the write was complete; this doesn't. The write can return zero for example, in which case the data will just be lost in your version. Maybe that's where your throughput is going?
    or OTOH does the computer you're running this on have more than 1 NIC? and if so is one slower than the other? You can see where I'm going with this.

Maybe you are looking for