SOCKET PROGRAMMING  HELP NEEDED!!!!

hi,
I got an idea of establishing socket connection with all clients from SERVER through the windows command
called (arp -a). when we type the stated command on dosprompt in server, it gives the list of current system's
ipaddress.....switched on. SO i can establish socket connections in a for loop where i can take the following ipaddress from output listed from command.
i've written the code to call the command in JAVA.
i write the dosprompt output in a file named list1.txt
import java.util.*;
import java.io.*;
import java.io.File;
public class RunCommand
public static String[] runCommand(String cmd) throws IOException
ArrayList list = new ArrayList();
Process proc = Runtime.getRuntime().exec(cmd);
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
String str;
while ((str = br.readLine()) != null)
list.add(str);
try
proc.waitFor();
}catch (InterruptedException e)
System.err.println("process was interrupted");
// check its exit value
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
br.close();
// return list of strings to caller
return (String[])list.toArray(new String[0]);
public static void main(String[] args) throws Exception
try
FileWriter f1=new FileWriter("list1.txt");
String[] s = runCommand("arp -a");
for (int i = 0; i< s.length; i++)
f1.write(s);
System.out.println(s[i]);
f1.close();
}catch (Exception ex) { System.out.println(ex);}
SAMPLE OUTPUT:
Interface: 172.16.3.1 on Interface 0x1000003
Internet Address Physical Address Type
172.16.3.4 00-00-e2-13-a9-e8 dynamic
172.16.3.6 00-00-e2-13-aa-0f dynamic
172.16.3.10 00-00-e2-13-ab-bb dynamic
172.16.3.12 00-00-e2-13-ab-93 dynamic
172.16.3.16 00-00-e2-13-37-b8 dynamic
172.16.3.17 00-00-e2-13-37-19 dynamic
172.16.3.18 00-00-e2-13-37-1d dynamic
172.16.3.19 00-00-e2-13-38-98 dynamic
172.16.3.22 00-00-e2-13-37-54 dynamic
172.16.3.23 00-00-e2-13-39-02 dynamic
172.16.3.24 00-00-e2-13-39-0f dynamic
172.16.3.26 00-00-e2-13-37-a5 dynamic
172.16.3.27 00-00-e2-13-37-0b dynamic
172.16.3.28 00-00-e2-13-37-12 dynamic
172.16.3.29 00-00-e2-13-39-15 dynamic
172.16.3.30 00-00-e2-13-38-af dynamic
172.16.3.31 00-00-e2-13-37-fe dynamic
172.16.3.32 00-00-e2-13-38-ff dynamic
172.16.3.34 00-00-e2-13-ab-c8 dynamic
172.16.3.37 00-00-e2-13-ab-67 dynamic
172.16.3.42 00-00-e2-13-ab-19 dynamic
PLS HELP ME OUT IN GETTING ONLY THE IPADDRESS IN FOR LOOP IN SERVER SOCKET PROGRAM TO INVOKE ALL CLIENT'S PROGRAM IN NETWORK.
PLS HELP ME!!!!!!!
ATTACH THE CODE!!!!!!!!!!!!

Connecting to a client presumes that the client is waiting for a connection.
If that is the case I would suggest looking a java.net.Socket.

Similar Messages

  • Socket Prorgramming HELP NEEDED!!!

    hi,
    I got an idea of establishing socket connection with all clients from SERVER through the windows command
    called (arp -a). when we type the stated command on dosprompt in server, it gives the list of current system's
    ipaddress.....switched on. SO i can establish socket connections in a for loop where i can take the following ipaddress from output listed from command.
    i've written the code to call the command in JAVA.
    i write the dosprompt output in a file named list1.txt
    import java.util.*;
    import java.io.*;
    import java.io.File;
    public class RunCommand
    public static String[] runCommand(String cmd) throws IOException
    ArrayList list = new ArrayList();
    Process proc = Runtime.getRuntime().exec(cmd);
    InputStream istr = proc.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(istr));
    String str;
    while ((str = br.readLine()) != null)
    list.add(str);
    try
    proc.waitFor();
    }catch (InterruptedException e)
    System.err.println("process was interrupted");
    // check its exit value
    if (proc.exitValue() != 0)
    System.err.println("exit value was non-zero");
    // close stream
    br.close();
    // return list of strings to caller
    return (String[])list.toArray(new String[0]);
    public static void main(String[] args) throws Exception
    try
    FileWriter f1=new FileWriter("list1.txt");
    String[] s = runCommand("arp -a");
    for (int i = 0; i< s.length; i++)
    f1.write(s);
    System.out.println(s[i]);
    f1.close();
    }catch (Exception ex) { System.out.println(ex);}
    SAMPLE OUTPUT:
    Interface: 172.16.3.1 on Interface 0x1000003
    Internet Address Physical Address Type
    172.16.3.4 00-00-e2-13-a9-e8 dynamic
    172.16.3.6 00-00-e2-13-aa-0f dynamic
    172.16.3.10 00-00-e2-13-ab-bb dynamic
    172.16.3.12 00-00-e2-13-ab-93 dynamic
    172.16.3.16 00-00-e2-13-37-b8 dynamic
    172.16.3.17 00-00-e2-13-37-19 dynamic
    172.16.3.18 00-00-e2-13-37-1d dynamic
    172.16.3.19 00-00-e2-13-38-98 dynamic
    172.16.3.22 00-00-e2-13-37-54 dynamic
    172.16.3.23 00-00-e2-13-39-02 dynamic
    172.16.3.24 00-00-e2-13-39-0f dynamic
    172.16.3.26 00-00-e2-13-37-a5 dynamic
    172.16.3.27 00-00-e2-13-37-0b dynamic
    172.16.3.28 00-00-e2-13-37-12 dynamic
    172.16.3.29 00-00-e2-13-39-15 dynamic
    172.16.3.30 00-00-e2-13-38-af dynamic
    172.16.3.31 00-00-e2-13-37-fe dynamic
    172.16.3.32 00-00-e2-13-38-ff dynamic
    172.16.3.34 00-00-e2-13-ab-c8 dynamic
    172.16.3.37 00-00-e2-13-ab-67 dynamic
    172.16.3.42 00-00-e2-13-ab-19 dynamic
    PLS HELP ME OUT IN GETTING ONLY THE IPADDRESS IN FOR LOOP IN SERVER SOCKET PROGRAM TO INVOKE ALL CLIENT'S PROGRAM IN NETWORK.
    PLS HELP ME!!!!!!!
    ATTACH THE CODE!!!!!!!!!!!!

    Cross post
    http://forum.java.sun.com/thread.jsp?thread=220281&forum=31&message=769848

  • EXPERT socket programmers help needed please!

    I basically have this very simple client/server app, where I can enter messages at the client to send to the server, and the server will display it on its screen.
    But how would I extend it to support multi client? So when I send messages from different clients, the server will diplay the message on its screen and also send the message back to all connected clients? Here's my current code
    Server:
    import java.net.*;
    import java.io.*;
    public class Server {
        public static void main(String[] args) throws IOException {
         ServerSocket serverSocket = new ServerSocket(5432);
         for (;;) {
             Socket clientSocket = null;
             try {
              clientSocket = serverSocket.accept();
             } catch (IOException e) {
              System.err.println("Accept failed.");
              System.exit(1);
             BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
             String nextline;
             while ((nextline = in.readLine())!=null) {
              System.out.println(nextline);
             in.close();
             clientSocket.close();
    }Client
    import java.io.*;
    import java.net.*;
    public class Client {
        public static void main(String[] args) throws IOException {
         Socket csocket = null;
         PrintWriter out = null;
         try {
             csocket = new Socket("localhost", 5432);
             out = new PrintWriter(csocket.getOutputStream(), true);
         } catch (IOException e) { }
         BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
         String nextline;
         while ((nextline = stdIn.readLine()) != null) {
             out.println(nextline);
         out.close();
         csocket.close();
         stdIn.close();
    }

    jverd wrote:
    javaguy86 wrote:
    But how would I extend it to support multi client?Ever hear of collections? Loops?Hardly the answer of an expert in Socket programming!!!!

  • Socket Based Server/Client Program Help Needed

    Alright,
    I am making a Client/Server program.
    The idea is that, when I run the 'Server' part, it sits and listens for a connection from the Client.
    The Client writes a string to the socket, then the server, interprets the command.
    This is what I have so far.
    The Server:
    public static void main(String[] args) {
             String clientLine = null;
              Socket channel = new Socket();
              try {
                   mainWin window = new mainWin();
                   window.open();
              } catch (Exception e) {
                   e.printStackTrace();
             try{
                   ServerSocket server = new ServerSocket(8313);
                  BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream()));
                 channel = server.accept();
                 clientLine = reader.readLine();
                 doCommand(clientLine);
                 reader.close();
                 channel.close();
                 server.close();
             catch(IOException ioe){
                  System.out.println("I/O Exception occurred while using the server");
         }The Client:
    public void sendCommand(String command){
              PrintStream socketWriter  = null;
              try{
                    Socket client = new Socket("127.0.0.1", 8313);
                    socketWriter = new PrintStream(client.getOutputStream());
                    socketWriter.println(command);
                    socketWriter.close();
                    client.close();
              }catch(UnknownHostException uhe){
              }catch(IOException ioe){
         }When I press the command button, it lags for a second, then does nothing.
    Does anyone see the problem?

    public static void main(String[] args) {
             String clientLine = null;
              Socket channel = new Socket(); //<-- This is connecting to where? nowhere, so initiate it to null instead.
              try {
                   mainWin window = new mainWin();
                   window.open();
              } catch (Exception e) {
                   e.printStackTrace();
             try{
                   ServerSocket server = new ServerSocket(8313);
                  BufferedReader reader = new BufferedReader(new InputStreamReader(channel.getInputStream())); //<-- Getting an input stream from nowhere?
                 channel = server.accept(); //<-- Perhaps you want to do this before you try to get the input stream from it?
                 clientLine = reader.readLine();
                 doCommand(clientLine);
                 reader.close();
                 channel.close();
                 server.close();
             catch(IOException ioe){
                  System.out.println("I/O Exception occurred while using the server");
         }

  • Basic Java Program help needed urgently.

    I have posted the instructions to my project assignment on here that is due tomorrow. I have spent an extremely large amount of time trying to get the basics of programming and am having some difficulty off of the bat. Someone who has more experience with this and could walk me through the steps is what I am hoping for. Any Help however will be greatly appreciated. I am putting in a lot of effort, but I am not getting the results I need. Thank you for the consideration of assisting me with my issues. If you have any questions please feel free to ask. I would love to open up a dialogue.
    CIS 120
    Mathematical Operators
    Project-1
    Max possible pts 100
    Write a program “MathOperators” that reads two integers, displays user’s name, sum, product,
    difference, quotients and modulus of the two numbers.
    1. Create a header for your project as follows:
    * Prgrammer: Your Name (1 pt) *
    * Class: CIS 120 (1 pt) *
    * Section: (1 pt) *
    * Instructor: (1 pt) *
    * Program Name: Mathematical Operators (1 pt) *
    * Description: This java program will ask the user to enter two integers and *
    display sum, product, difference, quotients and modulus of the two numbers
    * (5 pts) *
    2. Display a friendly message e.g. Good Morning!! (2 pts)
    3. Explain your program to the user e.g. This java program can add, subtract, multiply,
    divide and calculate remainder of any two integer numbers entered by you. Let’s get
    started…. (5 pts)
    4. Prompt the user- Please enter your first name, store the value entered by user in a
    string variable name. Use input.next() instead of input.nextLine(). (8 pts)
    5. Prompt the user- name, enter first integer number , store the value entered by user in
    an integer variable num1.(5 pts)
    6. Prompt the user- name, enter second integer number , store the value entered by user in
    an integer variable num2.(5 pts)
    7. Display the numbers entered by the user as: name has entered the numbers num1and
    num2.(5 pts)
    8. Calculate sum, product, difference, quotients and modulus of the two numbers. ( 30 pts)
    9. Display sum, product, difference, quotients and modulus of the two numbers. ( 10 pts)
    10. Terminate your program with a friendly message like- Thanks for using my program,
    have a nice day!!(2 pts)

    Nice try. You have not demonstrated that you've at least TRIED to do something. No one is going to do your homework for you. Your "urgency" is yours alone.

  • Dollar Change Program Help needed!!

    I need some immediate help writing a java program that determines change of 1 dollar recieved in the amout of quarters, dimes, and nickels when an item is purchased between the prices of 25cents and a dollar. For Example:
    Total Money: $1 (static)
    Enter the price of the item in cents: 45
    You bought an item for 45 cent and gave me a dollar, so your change is:
    2 quarters,
    0 dimes, and
    1 nickel.
    That is the basics of what I need, and I am not sure where to start.

    My program works as long as there is at least 1 penny to be given back in the change. I need help!
    //          CoinCounter.java
    //          This program counts the change given back from 1 dollar
    //          in specific values such as quarters, dimes, and nickels
    //          and pennies.
    //          Written By Jasen Hudson
    import javax.swing.*;
    import cs1.Keyboard;
    public class CoinCounter
    {// Begin class CoinCounter
         public static void main(String[] args)
              {// Begin main method
                   int cost = 0;
                   int dollar = 100;
                   int quarter = 25;
                   int dime = 10;
                   int nickel = 5;
                   int penny = 1;
                   int numQuarters = 0;
                   int numDimes = 0;
                   int numNickels = 0;
                   int numPennies = 0;
    //Item amount input
    String input = JOptionPane.showInputDialog
    ("Please enter the amount paid for the item.");
    cost = Integer.parseInt(input);
    //While statement
         int changeRequired = dollar - cost;
         while(changeRequired > 0){
              if((changeRequired - quarter>= 0){
              numQuarters ++;
                   changeRequired -= quarter;
                        continue;
              if(changeRequired - dime >= 0){
              numDimes ++;
                   changeRequired -= dime;
                        continue;
              if(changeRequired - nickel >= 0){
              numNickels ++;
                   changeRequired -= nickel;
                        continue;
              if(changeRequired - penny >= 0){
              numPennies ++;
                   changeRequired -= penny;
    //Amount of change needed to give back
         int change = dollar - cost;
    //System print out
         System.out.println("The change required for $1.00 from an item costing "
              + cost + " Cents is " +change+ ". Here is your change:");
              System.out.println(numQuarters+" Quarters");
              System.out.println(numDimes+" Dimes");
              System.out.println(numNickels+" Nickels");
              System.out.println(numPennies+" Pennies");
              System.exit(0);
    }

  • Socket programming help!

    Hi,
    i have to writte a socket file transfer client. I wrotte the code for the client and it connects to the server. But i dont know:
    1. how to pass the commands ls, get and quit to the server.
    2. client recognizes only small capitals but server big for example i client understands ls and server LS
    anyone can help me??
    thx in advance

    String.toUpperCase()
    String.toLowerCase()
    Runtime.exec()

  • Install program help needed

    I am trying to install a software program on my destop computer, I am the administrator, running 7 Home Premium, 64 bit, I downloaded the program but when I try to install "Installer failed to initialize".  I turned off the antivirus program, that did not help.  I contacted Adobe for help, I did what they said, turn off antivirus, redownload,tried to install and again "Installer failed to initialize".  Any ideas as to what I can do?

    When requesting help you should always include the make/model (i.e. p6-xxxx) of the computer and/or monitor. This information is necessary for us to review the specifications of them.
    What is the program?  I presume that it is an Adobe product.
    Signature:
    HP TouchPad - 1.2 GHz; 1 GB memory; 32 GB storage; WebOS/CyanogenMod 11(Kit Kat)
    HP 10 Plus; Android-Kit Kat; 1.0 GHz Allwinner A31 ARM Cortex A7 Quad Core Processor ; 2GB RAM Memory Long: 2 GB DDR3L SDRAM (1600MHz); 16GB disable eMMC 16GB v4.51
    HP Omen; i7-4710QH; 8 GB memory; 256 GB San Disk SSD; Win 8.1
    HP Photosmart 7520 AIO
    ++++++++++++++++++
    **Click the Thumbs Up+ to say 'Thanks' and the 'Accept as Solution' if I have solved your problem.**
    Intelligence is God given; Wisdom is the sum of our mistakes!
    I am not an HP employee.

  • Programing help needed  urgently

    Please help with my home work I'm really stuck
    Read in an integer from the keyboard, then check to see whether it is :
    Positive or not
    Even or odd
    A multiple of 7 or not
    The number must be displayed together with each of the tests.
    I don't know how to check for a multiple of seven that were I had a problem.
    Here is the program that I have written so far. It is in java.
    import java.util.Scanner;
    public class hwork11
    public static void main (String[]args)
    Scanner input=new Scanner (System.in);
    System.out.println("please enter a number");
    int num=input.nextInt(System.in);
    if(num>0)
    System.out.println(num+" is negative"):
    else
    System.out.println(num+" is positive");
    if( num%2 == 0)
    System.out.println(num+" even number");
    else
    System.out.println(num+" odd number");
    }

    Vee190 wrote:Please help with my home work I'm really stuck
    Read in an integer from the keyboard, then check to see whether it is :
    Positive or not
    Even or odd
    A multiple of 7 or not
    The number must be displayed together with each of the tests.
    I don't know how to check for a multiple of seven that were I had a problem.
    Here is the program that I have written so far. *{color:#0000ff}({color}* It is in java. *{color:#0000ff}r u kiddin me )*
    *{color}*
    import java.util.Scanner;
    public class hwork11
    public static void main (String[]args)
    Scanner input=new Scanner (System.in);
    System.out.println("please enter a number");
    int num=input.nextInt(System.in);
    if(num>0) *{color:#0000ff}( I think that numbers >0 are +. Whuddya think?){color}*
    System.out.println(num+" is negative"):
    else
    System.out.println(num+" is positive");
    if( num%2 == 0) *{color:#0000ff}If num is 4, do know why this statement is true? (num % 2 == 0)*
    **The key to answering your question about whether or not a number is a multiple of 7 is understanding the use of the % operator. Look it up, and figure it out. You will learn programming languages much faster if you understand what it is you are typing, rather than just trying to make a program by copying lines of code out of the book.*{color}*
    System.out.println(num+" even number");
    else
    System.out.println(num+" odd number");

  • Program help needed?

    1. class A555{
    2.     public static void main(String []args){
    3.          Boolean b1 = new Boolean(true);
    4. Boolean b2 = new Boolean(true);
    5. System.out.println( false +" " );
    6.     }
    7. }
    Regarding the above question, at line 5 if i use a boolean literal the program doesn't give any error but whenever i am using b1==b2 *(the two Boolean objects declared,initialized at 3 and 4)* in place of boolean literal, i am getting a compiler compiler error: incomparable types: java.lang.Boolean and java.lang.String . Kindly tell me what could be the reason?

    If you do:
    System.out.println(b1==b2 + " ");
    The compiler will try to make: b1 == (b2 + " ")
    so he is trying to add a string " " to the b2
    if you make: System.out.println((b1==b2) + " "); that should work
    this is a problem of precedence with the operators
    Hope this help!
    Alex

  • Some programming help needed

    I'm trying to make an alarm clock... I've done all the code but I don't know how to play sounds... I've seen that there is some sort of class for sounds with applets, but I didn't make an applet. It's just normal AWT... can anybody help me out? .....also, is there a more efficient way of 'updating' the clock-label? I used a while loop, but I don't think it's the way it's supposed to be done.
    thanks

    I am not sure what you mean by using a while loop to update the clock-label. I would have used a Timer class to change the time at the given intervals (say every second).

  • Game Programming help needed!

    Hi,
    I'm new to these forums just as i am fairly new to Flash Pro
    8, anyway i was mid way through creating my first flash game when i
    encountered this error message...
    **Error** Scene=Scene 2, layer=Layer 2, frame=25:Line 2: ')'
    or ',' expected
    gotoAndPlay('scene 2',frame 1);
    Total ActionScript Errors: 1 Reported Errors: 1
    it asks me to put an ')' or ',' in to the code but i just
    cant work out where it wans me to put it. Please Help!!!!!
    Thank You

    The parameters are wrong.
    The parameters should ne a scene name and a frame number or
    frame label on that scene.
    like . gotoAndPlay("myScene", 10);

  • New to Java Wireless Programming - Help needed!

    I'm currently finishing my 4 java programmign class in university, and i'm not looking to expand my knowledge in the this language. I would like to learn the how to code for wireless devices. I've already downloaded the Java Wireless Toolkit, but I would really appreciate some direction on what I should read to know where to start with this. Any info that anyone may have is greatly appreciated!
    Thanks
    Al

    Googling J2ME tutorials or MIDP tutorials will give you plenty to read.
    but here's a start:
    http://www.developer.com/java/j2me/article.php/10934_1561591_1
    http://developers.sun.com/techtopics/mobility/midp/samples/index.html#getstart

  • HELP NEEDED PLEASE

    Hi everyone
    Programming help needed here. Any advice would be greatly appreciated!!!
    I have been assigned some work for a program called Processing 1.0 availale at http://processing.org/download
    I was give the 9 individual programs I needed to make however they were converted to Java files from .pde files. The program is based on Java but only runs .pde files and NOTHING else!
    I decompiled the files and got the source code, but it is a slight variation of the original someone made in processing, and needs some tidying to get it to run.
    I think the programs are very simple for a programmer, although I AM NOT.
    CODE is BELOW
    // Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov Date: 02/05/2009 13:15:00
    // Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
    // Decompiler options: packimports(3)
    // Source File Name: Assign2_1.java
    import processing.core.PApplet;
    public class Assign2_1 extends PApplet
    public Assign2_1()
    SquareSide = 20;
    Rank = Nums.length;
    Side = SquareSide * Rank;
    Green = color(0, 255, 0);
    Yellow = color(255, 255, 0);
    BG = Yellow;
    public void setup()
    size(Side, Side);
    background(BG);
    fill(Green);
    for(int i = 0; i < Rank; i++)
    rect(i * SquareSide, 0.0F, SquareSide, SquareSide * Nums);
    public static void main(String args[])
    PApplet.main(new String[] {
    "--bgcolor=#ece9d8", "Assign2_1"
    int Nums[] = {
    6, 14, 8, 9, 2, 3, 4, 2, 8, 3,
    9, 2, 0, 5
    int SquareSide;
    int Rank;
    int Side;
    int Green;
    int Yellow;
    int BG;
    Edited by: chevy1 on May 2, 2009 7:32 AM

    HELP NEEDED PLEASEShouting is a good way ensure you don't get help. Also you should give a meaningful subject.
    Any advice would be greatly appreciated!!!I suggest you ask a question after providing enough information to be able to answer it.
    Also use CODE tags when posting code as it make the code more readable.
    We are more likely to help people who are trying to learn Java rather than someone who might be looking for an easy way out of doing an assignment.

  • Help needed with swings for socket Programming

    Im working on a Project for my MScIT on Distributed Computing...which involves socket programming(UDP)....im working on some algorithms like Token Ring, Message Passing interface, Byzantine, Clock Syncronisation...i hav almost finished working on these algorithms...but now i wanna give a good look to my programs..using swings but im very new to swings...so can anyone help me with some examples involving swings with socket programming...any reference...any help would be appreciated...please help im running out of time..
    thanking u in advance
    anDy

    hi im Anand(AnDY),
    i hav lost my AnDY account..plz reply to this topic keeping me in mind :p

Maybe you are looking for