Java Network Programming using UDP protocol

I am trying to send the object using UDP protocol.
In my client class it is giving me NullPointer excetion at clientSocket.send(sendPacket); although sendPacket is not null it has the value that I am passing.
Here is the code :
private boolean clientSrvrComm(AuditorData audData) throws Exception
          boolean result = false;
          ByteArrayOutputStream barray_out = new ByteArrayOutputStream();
          ObjectOutputStream obj_out = new ObjectOutputStream(barray_out);
          obj_out.flush();
          obj_out.writeObject(audData);
          obj_out.flush();
          // sending the data to the server
          byte[] sendData = barray_out.toByteArray();
          DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length,IPAddress,serverPort);
          clientSocket.send(sendPacket); // getting exception at this line
          return result;
     } // method end
I am passing audData through main method.
Any help would be appreciate.
Thanks,
Swati

actually it shouldn't give the null pointer exception and send the object to the server.
I am not able to get, why it is throwing the exception, even there is no class for debugging.

Similar Messages

  • Advanced Java network programming

    I have been playing around with the various Server/Client tutorials not only on this site but many others for some time now. Whilst I have learnt a great deal I am now trying to further my knowledge.
    The problem is, there does not seem to be a great deal of information on the Web realting to the advanced network programming stuff. Obviously not having a network of my own I am now interested in learning various ideas using the Internet. Obviously not being a prat about it and port scanning other computers or anything like that.
    I was hoping someone reading this might have a suggestion about where to go next in my learning curve. Also if anyone could recommend any good sources of info for this type of stuff.
    I've currently got three telephone lines in, each line with a seperate Internet account set-up. What I want to do is have them all connected to the web at once and then attempt various things, such as connection, that type of stuff.
    Help really appreciated.
    Thanks,
    kP

    Maybe I'm catching the wrong vibe here, but it seems to me that you need to learn a bit about networking in general, before you worry about how it's all done in java. I would suggest a good basic computer networking text book. After you have good understanding of how different networks works, packet structure of the various common protocols, IP, TCP over IP and UDP over IP. I think the java code to implement it all will just fall into place. my AIM SN is SpinozaQ if you would like a book suggestion. I don't have any names going through my head right now.

  • Desperately need Java network programming help!!!

    I need to make a Distributed File Sharing System (DFSS) using java language. The system should not make use of the central file server. The system should coordinate the concurrent access of files over the distributed environment. Caching may be used to enhance the system performance.
    It is basically network programming.
    Does any one have any idea how to make the DFSS. If you do please help!!!
    thank you in advance for you help
    cheers

    well, you're getting somewhere I guess. My original answer was intentionally vague because your original question was so vague. These fora are no good for asking questions like "how do I implement a distributed file system", they are good for asking things like "the following line(s) of code generate the following condition I didn't expect, rather I expected this condition, could someone tell me what is going on?" or something of similar specificity.
    So you are now asking how to, for instance, check to see if a text file is being shared. This is still too vague, but it's better than "how do I write a file sharing system". If you are feeling particularly industrious, go look at a project JXTA at http://www.jxta.org/ - it's open source, you can look at the code. Of course, if you're brand new, this might not help. In fact, not to discourage you, but if you're that new, this is not the project to be doing.
    Good Luck
    Lee

  • Where can I find knowledge about "java network programming"?

    I am interested in network programming in java. I need some documents and I don't where can I find it?

    http://java.sun.com/docs/books/tutorial/networking/index.html

  • Related to Network program using Java Client and C server

    I am little bit experience in java technology. I need an urgent help as I have to submit a document related to C server and Java client. But while searching in net i cant get a proper guidance for C server as many errors thrown in sys/socket.h and other new header files. Can any one help me out for giving source code for C Server. so that i can further involve in that document. Please help me out. i am really helpless by the way the C server thrown error. after finishing that C server only i can concentrate on Java client...

    Hai Josah,
    Thanks for your reply.. I have gone through many sockets server program in C but the real proble is the header file they include like
    socket.h and in.h etc.. they also provide these header files but if we compile in turboC they inturn require some other header files. I dont get the full hierarchy of C server program. I found some help in Java programming Archive about C Server and java client. As i am new to C i cant get the full header files for the server.c if i complete taht only i can proceed to java client. If u can redirect me for any good C sites also i can be thankful for u forever..please

  • Java Network Programming

    I am trying to make a Third-party chat client an alternative of rediffbol for rediffchat
    * To do this, I downloaded a packet sniffer (Sniphere) and started monitoring the packets sent and received by the original Rediff messenger.*
    * Rediff Bol uses the MSNP protocol to connect...*
    *1. First the client establishes a tcp connection with the DISPATCH server "203.199.83.62 : 1863"*
    *2. then the client sends the DISPATCH server its VERSION and a command so that the dispatch server can send back a list of available notification servers...*
    *3. Then the DISPATCH server sends back the client a list of available NOTIFICATION servers......the client connects there and like this it goes on...*
    I am using Java. I captured the packet 2. where the command the and the version is sent. I sent the exact packet to the server but due to some reason the dispatch server is not sending back the list of NOTIFICATION servers...
    the client.java is attached
    there is a difference of negotiation that is occuring between my prog-server and rediffmessenger-server
    its like this
    pck 1<client-outgoing>: 2<server-incoming> and 3<client-outgoing> which I think is a three way handshaking...its same with my program as the original rediffmessenger
    pck 4: this in case of the rediffmessenger is the command and version<outgoing>...same in my case
    pck5:  this is supposed to be an incoming stream from server 203.199.83.62:1863 which will have the data of available notification servers......WHICH in my case is becoming an outgoing packet from my client<i didnt send anything except the command , refer to client.java> which contains nothing as DATA...and in the later packets the server never sends the list of notification servers...

    import java.net.*;
    import java.nio.*;
    import java.nio.charset.*;
    import java.nio.charset.Charset;
    import java.io.*;
    import java.io.FileOutputStream;
    class client extends Object implements java.io.Serializable
    private static byte[] getBytes (char[] chars)
    Charset cs = Charset.forName ("UTF-8");
    CharBuffer cb = CharBuffer.allocate (chars.length);
    cb.put (chars);
    cb.flip ();
    ByteBuffer bb = cs.encode (cb);
    return bb.array();
    public static void main( String args[] )
    File f2=new File("data.dat");
    int decimal_value;
    char[] extract_char;
    extract_char=new char[2];
    char[] dat;
    byte[] bytes=new byte[19];
    byte[] bytes2=new byte[19];
    String str;
    int count=0;
    dat=new char[19];
    String getloginserver="564552203134204D534E503820435652300D0A"; //The data packet to ask for notification servers(Hex Dump)
    //coverting it into byte array--THIS PART IS WORKING OKAY
    for(int i=0;i<(getloginserver.length()-1);i+=2)
    extract_char[0]=getloginserver.charAt(i);
    extract_char[1]=getloginserver.charAt(i+1);
    str=Character.toString(extract_char[0])+Character.toString(extract_char[1]);
    decimal_value=Integer.parseInt(str, 16);
    dat[count++]=(char)decimal_value;
    count=0;
    bytes=getBytes(dat);
    //for(int j=0;j<30;j++)
    //System.out.print((char)bytes[j]);
    for(int j=1;j<19;j++)
    bytes2[j-1]=bytes[j];
    //converting hex dump to byte array completed
    // bytes2[] is the byte array which contains the command for the server..it has to be sent...
    //establish connection and send
    try
    Socket toServer;
    toServer = new Socket ("65.54.239.80",1863);
    OutputStream os = toServer.getOutputStream();
    os.write(bytes2);
    os.flush();
    catch ( IOException e )
    System.out.println("Cannot write to the server " + e );
    Thats why i didnt post code....its big....

  • Help needed for java network programming

    How can I implement a GUI as a client in my server-client program.
    I have a window(JFrame)having one Textfield and a "Send" button.
    My requirement: While execution, the GUI should start as a client, and whatever textinput I will give to the Textfield, that should be printed in the server program.
    So, how can I implement a GUI window as a client.
    If any of U have idea,Please let me know soon.
    Regards.

    Well, the client part and the GUI part are separate. The button simply calls a send method.
    As for the networking, you can just use a Socket and a ServerSocket on the client and server, respectively. Then, wrap a PrintStream around one side and a BufferedReader(InputStreamReader()) around the other. You'll be able to talk back and forth once your connection is established; it's up to you to read from the BufferedReader and use the results on the server side.

  • New in Java: java applet program using multithreading

    I am trying to write a program, which should move the words "Java Platform2" from left to right every time we 'refresh'.
    Can you please advise what is wrong in the logic??
    import java.applet.*;
    import java.awt.*;
    import java.lang.*;
    public class Ch61appth extends Applet implements Runnable
    int i=30;
    int x=10;
    int y=30;
    Thread t,cur;
         public void start()
              t=new Thread(this);
              t.start();
         public void paint(Graphics g)
              g.setColor(Color.blue);
              g.drawString("Java Platform2",x+i,y);
         public void run()
                   if ((x+i)<400)
                        {     i=i+20;
                        else
                        {     i=20;
              //cur=new Thread.currentThread();
              repaint();

    thanks for reply
    i tried using for loop. Earlier also i had tried using while loop with condition t==Thread.currentThread()
    The problem i am facing is the string just does not move and even after clicking refresh, it appears at same locations.
    CAN U ADVISE>
    bye
    kumar

  • Creating variables in a java swing program useing event

    This is my code:
    *Old School Calculator
    *@Collin Doering
    *Version 2.00
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class OSC {
         private static void createAndShowGUI() {
              int first = 0;
              int second = 0;
              int third = 0;
              int fourth = 0;
              int fifth = 0;
              int answer;
              System.out.println ("Calculations");
              System.out.println ("-------------");
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame frame = new JFrame("OSC");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("1");
    button1.setMnemonic(1);
    button1.addActionListener
         new ActionListener() {
              public void actionPerformed (ActionEvent e) {
    first = 1;
    //This is when the error says "Local variable first is accesed from
    with in inner class; needs to be declared final;
                   System.out.println ("first = ");
    JButton button2 = new JButton("2");
    button2.setMnemonic(2);
    button2.addActionListener
         new ActionListener() {
              public void actionPerformed (ActionEvent e) {
                   System.out.println ("Second = ");
    JButton buttonx = new JButton("x");
    buttonx.addActionListener
         new ActionListener() {
              public void actionPerformed (ActionEvent e) {
                   System.out.println ("answer: ");
    JPanel panel = new JPanel(new GridLayout(10,10));
    panel.add(button1);
              panel.add(button2);
              panel.add(buttonx);
              frame.getContentPane().add(panel);
    panel.setBorder(BorderFactory.createEmptyBorder(
    30, //top
    30, //left
    10, //bottom
    30) //right
    frame.pack();
    frame.setVisible(true);
         public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    I am trying to create variables so i can make a calculator (right now i only have buttons 1, 1 and multiply). //This is when the error says "Local variable first is accesed from
    with in inner class; needs to be declared final; then when i declare it final it says <identifier expected>. Could some one please help me. thanx.

    Please post code within code tags (press the "code" button).
    Why are you using an inner class? Simplify:
    public class OSC implements ActionListener {
    button1.addActionListener( this );
    public void actionPerformed( ActionEvent e ) {
        if ( e.getSource() == button1 ) . . .

  • Java/jsp programing using timer

    what I want to do is say
    at 8am every day
    send email news letter to all members on the database.
    without the press of a button on my side.
    anyone done such programing with java?
    Sample codes will bve much appreciated.
    Thanks in advance

    This sounds a good idea nut that means the hosting co
    have to allow the OS job to trigger it az 8 pm on
    their system because something has to be on
    permanently for it to happen.Well, that is information you might have given right away. In that case, you might be short of luck for a reliable way to do it. At least I can't think of a way - if all you can do is call a servlet, you'll need to activate it on 8 am yourself daily. I don't think you can make the servlet run in an endless loop that keeps it "alive" for eternity, to repeatedly trigger the mailing. I mean you probably can, but my bet is that it gets killed by the container after a certain timeout.

  • Java networking program

    Dear Sir,
    I amstudying in Deakin International for MIT course and my main subject is java networkprogramming but i feel it diffcuilt.We have diferent assignments so please send me some tutorials or notes based on this subject please also some programming codes also based on each topic as it is hard for me
    thankyou

    http://java.sun.com/docs/books/tutorial/

  • Simple Java Network Programming Question

    import java.io.*;
    import java.net.*;
    public class ConsumerClient
         private static InetAddress host;
         private static final int PORT = 1234;
         private static Socket link;
         private static Resource item;
         private static BufferedReader in;
         private static PrintWriter out;
         private static BufferedReader keyboard;
         public static void main(String[] args)     throws IOException
              try
                   host = InetAddress.getLocalHost();
                   link = new Socket(host, PORT);
                   in = new BufferedReader(new InputStreamReader(link.getInputStream()));
                   out = new PrintWriter(link.getOutputStream(),true);
                   keyboard = new BufferedReader(new InputStreamReader(System.in));
                   String message, response;
                   do
                        System.out.print("Enter 1 for resource or 0 to quit: ");
                        message = keyboard.readLine();
         if(message.equals("1")**
                             item.takeOne();**
                        //Send message to server on
                        //the socket's output stream...
                        out.println(message);
                        //Accept response from server on
                        //the socket's input stream...
                        response = in.readLine();
                        //Display server's response to user...
                        System.out.println(response);
                   }while (!message.equals("0"));
              catch(UnknownHostException uhEx)
                   System.out.println("\nHost ID not found!\n");
              catch(IOException ioEx)
                   ioEx.printStackTrace();
              finally
                   try
                        if (link!=null)
                             System.out.println("Closing down connection...");
                             link.close();
                   catch(IOException ioEx)
                        ioEx.printStackTrace();
    }

    georgemc wrote:
    BlueNo yel-- Auuuuuuuugh!
    But the real question is: What is the air-speed velocity of an unladen swallow?

  • Java network programming explanation

    I have refer to following code, i not so understand, can somebody explain it to me? Thanks
    try {
    e = NetworkInterface.getNetworkInterfaces();
    while (e != null && e.hasMoreElements()) {
    NetworkInterface net = (NetworkInterface) e.nextElement();
    Enumeration enum = net.getInetAddresses();
    while (enum.hasMoreElements()) {
    InetAddress inet = (InetAddress) enum.nextElement();
    new FileServerThread(inet);
    catch (SocketException ex) {
    }

    try {
        // get an Enumeration of network interfaces
        e = NetworkInterface.getNetworkInterfaces();
        // iterate through the Enumeration
        while (e != null && e.hasMoreElements()) {
            // retrieve the next individual NetworkInterface object from
            // the enumeration
            NetworkInterface net = (NetworkInterface) e.nextElement();
            // get the enumeration of InetAddresses from the
            // NetworkInterface
            Enumeration enum = net.getInetAddresses();
            // iterate through the InetAddresses
            while (enum.hasMoreElements()) {
                // get the next InetAddress object from the enumeration
                InetAddress inet = (InetAddress) enum.nextElement();
                // instantiate a new FileServerThread for the given
                // InetAddress
                new FileServerThread(inet);
    // catch any thrown Exception objects
    catch (SocketException ex) {
    } What questions are you having about this pretty basic piece of code?

  • How to write JDBC code in a java thread? for network programming

    Hii guys, i am new to java network programming. I developed small swing application for stock controlling in a shop, so i need to run the database in a server. i try the peer to peer scenario, but the response is too late and the application get stuck. there i wl put my data base java class
    please help me for this, how can i change this java class to networked JDBC
    import com.mysql.jdbc.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    public class ConnectionSet {
    private String severIp = "localhost";
    private String severPort = "3306";
    private String userName = "root";
    private String password = "123";
    private ResultSet rs;
    public void setSeverIp(String Ip) {
    severIp = Ip;
    public void setSeverPort(String Port) {
    severPort = Port;
    public void SetUserName(String Name) {
    userName = Name;
    public void setPassword(String passWord) {
    password = passWord;
    public ResultSet getResult(String url) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection cc = (Connection) DriverManager.getConnection("jdbc:mysql://" + getSeverIp() + ":" + getSeverPort() + "/suriyalanka", getUserName(), getPassword());
    Statement s = cc.createStatement();
    rs = s.executeQuery(url);
    // java.sql.ResultSet rs = (ResultSet) DriverManager.getConnection("jdbc:mysql://"+getSeverIp()+":"+getSeverPort()+"/suriyalanka",getUserName(), getPassword()).createStatement().executeQuery(url);
    return rs;
    public Connection getConnection() throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection cc = (Connection) DriverManager.getConnection("jdbc:mysql://" + getSeverIp() + ":" + getSeverPort() + "/suriyalanka", getUserName(), getPassword());
    return cc;
    public void setResult(String url) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection cc = (Connection) DriverManager.getConnection("jdbc:mysql://" + getSeverIp() + ":" + getSeverPort() + "/suriyalanka", getUserName(), getPassword());
    Statement s = (Statement) cc.createStatement();
    s.executeUpdate(url);
    public String getSeverIp() {
    return severIp;
    public String getSeverPort() {
    return severPort;
    public String getUserName() {
    return userName;
    public String getPassword() {
    return password;
    please help me for this, how can i change this java class to networked JDBC
    Edited by: 798670 on Sep 29, 2010 6:04 AM

    Have you verified that your mysql allows network connections?
    In order to allow network connections you have to comment or remove line "skip-networking" in my.ini(windows) or my.cnf(unix) configuration files of your mysql instance.
    Or if you have the mysql administrator installed
    MySQL Administrator / Startup Variables / Disable networking (uncheck)
    By!

  • Network Programming exam papers (college exam papers)

    hello.
    my name is james mcfadden and i am a final year (4th year) undergraduate computing student at Letterkenny Institute of Technology. my e-mail address is [email protected] I have a question here for you. Would you have links to online versions of final year undergraduate Computing exam papers, specifically Networked Applications Development and or Network Management exam papers? I was only able to get access to Trinity College Dublin�s exam papers and Letterkenny IT�s exam papers.
    The 2005/06 academic year is the 1st academic year that final year undergraduate computing students at Letterkenny IT are being taught how to continue doing network programming in Java. i was taught how to do simple network programs in Java when I was in 3rd year.
    The name of the network programming subject that I�m doing in 4th year is Network Programming for Broadband Systems. It is divided into 2 parts: Programming and Networks. In past exam papers (C++ papers), a student would have had to answer 4 out of 6 questions. There would�ve been 4 programming questions and 2 networking questions on those papers. It is going to be the same for both the Summer and Autumn 2007 Broadband Network Programming exam papers, apart from fact that they will be Java papers and that a lot of the material that I have learned is new.
    In 4th year I did Multicast Sockets, Threads, Non-Blocking I/O, Remote Method Invocation, Protocol Handlers, and Content Handlers for the Programming part of the subject (Java Network Programming, 3rd Edition, by Elliote Rusty Harold).
    I did Network Security and Network Management for the Networks part of the subject (Computer Networking : A Top-Down Approach Featuring The Internet, 3rd Edition, by James F. Kurose and Keith W. Ross).
    Your help is greatly appreciated.
    Thank you.

    I have a question here for you.
    Would you have links to online versions of final year
    undergraduate Computing exam papers, specifically
    Networked Applications Development and or Network
    Management exam papers? No

Maybe you are looking for