Creating server/client program to send images

Hi, I'm trying to create a program where the server and client can send pictures to each other. I don't really know where to start. I want to try to work on the most tedious part of the program first.
A rough image of how it would execute in the following order:
1.User type in their username
2.User selects if they are the server or client
3.User types in IP address/route number (kind of fuzzy on this one)
4.The window for transferring photo
Thank you very much.
(I'm new at programming, but my goal is to try to develop the program with minimum help from my friends as possible.)

The best thing to do is to get introduced to the API that you will be using. The most difficult part will be establishing a connection to from client to server and sending/receiving data. Look at the Java API here: http://java.sun.com/javase/6/docs/api/ and scroll down the left side to the URLConnection class, which is the one you will use for the communication.
When using URLConnection, see http://www.javaworld.com/javaworld/jw-03-2001/jw-0323-traps.html to help get around some of the traps in using it.
Start with two separate programs, one server and one client. Make both programs command line applications, and don't worry about users etc.. to start with. Maybe even use a fixed IP address and Port for the server. Start with sending text back and forth, and when you get that down switch to images. Then worry about the user interface, logging in, selecting images to serve, location to save to, etc...

Similar Messages

  • Need an example of server / client program with swing interface

    Hi!
    After a lot of trying i still haven't managed to create a server client program using swing components ...
    can someone write a mini application to demonstrate how this can be done?
    i would like to have a frame with a button a texField for input and a textAread for the output
    What i have in mind is the following ..
    say im the server
    i write something in the textField and then i press the button
    then the information written in the textFiled is passed to the client who shows it in his textArea
    The same thing goes on with the client (he can write something in his own textField and when he presses the button the info is passed at the
    server who puts it in his textArea) and vice versa.
    i have written many classes that trying unsuccessfully to do that ... below i show my last attempt ...
    I would appreciate if you could write a small application which it could to this.
    The whole idea is to create a turn based game ( i have implemented the game engine and graphics and i try to add the internet function)
    Here is the code ...( i would appreciate if you write a new code instead of trying to correct mine ( which i think it's impossible) in order to use it as a general example)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    @SuppressWarnings("serial")
    *  In order to have a more gereral program instead of passing strings between the server
    *  and the client a pass an MyObjext object.  The MyObject class has an integer and a String
    *  (which is always the same) field . At the textField i write an integer number and i
    *  make a new MyObject which i want to pass to the server or the client and vice versa.
    *  The textArea shows the integer value of the MyObject which was passed from the server /client
    public class MyUserInterface extends JFrame {
         MyObject returnObject;
         JTextField myTextField;
         JTextArea te ;
         ClientGame cg;
         ServerGame sg;
          * used to determine if the current instance is running as a client or host
         boolean isHost;
         //The constructor of the client
         public MyUserInterface(ClientGame cg){
              this("Client");
              this.cg = cg;
              isHost = false;
         //The constructor of the server
         public MyUserInterface(ServerGame sg){
              this("Server");
              this.sg = sg;
              isHost = true;
         //The general constructor used both by client and server ..
         // it initializes the GUi components and add an actionListenr to the button
         public MyUserInterface(String str) {
              super(str);
              myTextField = new JTextField(2);
              te = new JTextArea();
              te.setPreferredSize(new Dimension(100,100));
              JButton okButton = new JButton("Ok");
              okButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        try{
                             int a = Integer.parseInt(MyUserInterface.this.myTextField.getText());
                             System.out.println(a);   //used to control the flow of the program
                                  MyUserInterface.this.returnObject = new MyObject(a);
                             //sends the data
                             sendData();
                             //waiting for response...
                             getData();
                             catch(Exception ex){System.out.println("Error in the UI action command" +
                                                                ex.printStackTrace();}
              JPanel panel =  new JPanel(new FlowLayout());
              panel.add(okButton);
              panel.add(myTextField);
              panel.add(te);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              getContentPane().add(panel);
              pack();
              setVisible(true);
         protected MyObject getReturnObject() {
              return returnObject;
         public void sendData(){
              new Thread(new Runnable() {
                   @Override
                   public void run() { 
                        if (!isHost)cg.sentData(returnObject);    //using the Servers out and in methods
                        else sg.sentData(returnObject);                    //using the Clients out and in methods
                        System.out.println("data sending");
         public MyObject getData(){
              MyObject obj;
              System.out.println("Retrieveing Data");
              if (!isHost)obj = (MyObject)cg.getData();
              else obj = (MyObject)sg.getData();
              System.out.println(" data retrieved  = "+ obj.getInt());  //just to control how the code flows
              te.setText(obj.getInt()+"");       
              return obj;
         public static void main(String[] args) {
              *Initiating the Server
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        ServerGame sg = new ServerGame();
                        new MyUserInterface(sg);
              }).start();     
               * Initiating the Client
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        ClientGame cg = new ClientGame("192.168.178.21");   //<----in case you run my code
                                                                          //..don't forget to change to your
                        new MyUserInterface(cg);                              //ip
              }).start();
    import java.io.*;
    import java.net.*;
    public class ClientGame {
         String ipAddress;
         Socket clientSocket = null;
        ObjectOutputStream out = null;
        ObjectInputStream in = null;
         public ClientGame(String ipAddress) {
              this.ipAddress = ipAddress;
              try {
                   System.out.println("Connecting To Host");
                 clientSocket = new Socket(InetAddress.getByName(ipAddress),4444);
                System.out.println("Host Found ...Io initializaton");
                out = new ObjectOutputStream(clientSocket.getOutputStream());
                in = new ObjectInputStream(clientSocket.getInputStream());
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host: taranis.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to: taranis.");
                System.exit(1);
         public Object getData(){
              Object fromServer = null ;
              do{
                 try {
                      fromServer = in.readObject();
                 catch(ClassNotFoundException ex){}
                  catch(IOException e){}
              }while(fromServer==null);
              return fromServer;        
         public void sentData(final Object obj){
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        try{
                             out.writeObject(obj);
                        catch(IOException e){}
              }).start();
         public void terminateConnection(){
              try{
                   out.close();
                   in.close();
                   clientSocket.close();
              catch (IOException e){}
    public class ServerGame {
         ServerSocket serverSocket;
         Socket clientSocket;
         ObjectOutputStream out = null;
        ObjectInputStream in = null;
         public ServerGame() {
              try{
                   serverSocket = new ServerSocket(4444);
                   clientSocket = serverSocket.accept();
                   out =  new ObjectOutputStream(clientSocket.getOutputStream());
                in = new ObjectInputStream(clientSocket.getInputStream());
              catch(IOException e){System.out.println("IOException in ServerGame");}
         public Object getData(){
              Object fromClient = null ;
              do{
                 try {
                      fromClient = in.readObject();
                 catch(ClassNotFoundException ex){}
                  catch(IOException e){}
              }while(fromClient==null);
             return fromClient;        
         public void sentData(final Object obj){
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        try{
                   out.writeObject(obj);
              catch(IOException e){}
              }).start();
         public void terminateConnection(){
              try{
                   out.close();
                   in.close();
                   clientSocket.close();
                   serverSocket.close();
              catch (IOException e){}
         public static void main(String[] args) {
              new ServerGame();
    import java.io.Serializable;
    * this is a test object
    * it has a String field and a value
    *  The string is always the same but the integer value is defined in the constructor
    public class MyObject implements Serializable{
         private static final long serialVersionUID = 1L;
         String str;
         int myInt;
         MyObject(int a){
              str = "A String";
              myInt = a;
         public int getInt(){
              return myInt;
    }

    Pitelk wrote:
    I believe that a good code example can teach you things ;that you would need many days of searching; in no timeSo lets write one small example.. Ill help a little, but you do most of the work.
    jverd approach is deffenetly the way to go.
    jverd wrote:
    * Write a very small, simple Swing program with an input area, an output area, and a button. When you click the button, what's in the input area gets copied over to the output area.This part is partially done.
    * Write a very small, simple client/server program without Swing. It should just send a couple of hardcoded messages back and forth.And this part is for you(Pitelk) to continue on. I cannot say that this is the best way. or that its good in any way. I do however like to write my client/server programs like this. And perhaps, and hopefully, Ill learn something new from this as well.
    This is how far I got in about 10-20min..
    package client;
    * To be added;
    * A connect method. That connects the client to the server and
    * opens up both the receive and transmit streams. After doing that
    * the an instance of the ServerListener class should be made.
    * Also an disconnect method could be usable. But thats a later part.
    public class TestClass1 {
    package utils;
    import java.io.ObjectInputStream;
    import client.TestClass1;
    * This class is meant to be listening to all responses given from
    * the server to the client. After a have received data from the
    * server. It should be forwarded to the client, in this case
    * TestClass1.
    public class ServerListener implements Runnable {
         public ServerListener(ObjectInputStream in, TestClass1 tc) {
         @Override
         public void run() {
              while(true) {
    package server;
    import java.io.ObjectOutputStream;
    import java.net.Socket;
    import java.util.ArrayList;
    import java.util.List;
    * This class should handle all data sent to the server from the clients.
    class Server implements Runnable {
         private static List<ObjectOutputStream> outStreams = new ArrayList<ObjectOutputStream>();
         private Socket client = null;
         public Server(Socket client) {
              this.client = client;
         @Override
         public void run() {
              while(true) {
    * The meaning of this class is to listen for clients trying to connect
    * to the server. Once connection is achieved a new thread for that client
    * should be made to listen for data sent by the client to the server.
    public class ChatServer implements Runnable {
         @Override
         public void run() {
              while(true) {
    package utils;
    import java.io.Serializable;
    @SuppressWarnings("serial")
    public class MyObject implements Serializable {
         private String mssg;
         private String clientID;
         private String clientName;
         public MyObject(String mssg, String clientID, String clientName) {
              this.mssg = mssg;
              this.clientID = clientID;
              this.clientName = clientName;
         //Generate getters and setters..
    }Continue on this, and when you get into problems etc post them. Also show with a small regular basis how far you have gotten with each class or it might be seen as you have lost intresst and then this thread is dead.
    EDIT: I should probably also say that Im not more than a java novice, at the verry most. So I cannot guarantee that I alone will be able to solve all the problems that might occure during this. But Im gonna try and help with the future problems that may(most likely will) occure atleast(Trying to reserve my self incase of misserable failiure from me in this attempt).
    Edited by: prigas on Jul 7, 2008 1:47 AM

  • My first Server/Client Program .... in advise/help

    Hello,
    I am learning about Sockets and ServerSockets and how I can use the. I am trying to make the simplest server/client program possible just for my understanding before I go deper into it. I have written two programs. theserver.java and theclient.java the sere code looks like this....
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class theserver
      public static void main(String[] args)
      {   //  IOReader r = new IOReader();
            int prt = 3333;
            BufferedReader in;
             PrintWriter out;
            ServerSocket serverSocket;
            Socket clientSocket = null;
    try{
    serverSocket = new ServerSocket(prt);  // creates the socket looking on prt (3333)
    System.out.println("The Server is now running...");
    while(true)
        clientSocket = serverSocket.accept(); // accepts the connenction
        clientSocket.getKeepAlive(); // keeps the connection alive
        out = new PrintWriter(clientSocket.getOutputStream(),true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
         if(in.ready())
         System.out.println(in.readLine()); // print it
    catch (IOException e) {
        System.out.println("Accept failed:"+prt);
    and the client looks like this
    import java.net.*;
    import java.io.*;
    public class theclient
    public static void main(String[] args)
        BufferedReader in;
        PrintWriter out;
        IOReader r = new IOReader();
        PrintWriter sender;
        Socket sock;
      try{
        sock = new Socket("linuxcomp",3333);  // creates a new connection with the server.
        sock.setKeepAlive(true); // keeps the connection alive
        System.out.println("Socket is connected"); // confirms socket is connected.
        System.out.println("Please enter a String");
         String bob = r.readS();
          out = new PrintWriter(sock.getOutputStream(),true);
        out.print(bob); // write bob to the server
      catch(IOException e)
           System.out.println("The socket is now disconnected..");
    If you notice in the code I use a class I made called IOReader. All that class is, is a buffered reader for my System.in. (just makes it easier for me)
    Ok now for my question:
    When I run this program I run the server first then the client. I type "hello" into my system.in but on my server side, it prints "null" I can't figure out what I am doing wrong, if I am not converting correctly, or if the message is not ever being sent. I tried putting a while(in.read()) { System.out.println("whatever") } it never reaches a point where in.ready() == true. Kinda of agrivating. Because I am very new to sockets, I wanna aks if there is somthing wrong with my code, or if I am going about this process completely wrong. Thank you to how ever helps me,
    Cobbweb

    here's my simple server/client Socket :
    Server:
    import java.net.*;
    import java.io.*;
    public class server
       public static void main(String a[])
              ServerSocket server=null;
              Socket socket=null;
              DataInputStream input=null;
              PrintStream output=null;
          try
             server=new ServerSocket(2000);
             socket=server.accept();
             input = new DataInputStream(socket.getInputStream());
             output = new PrintStream(socket.getOutputStream());
             //output.println("From Server: hello there!");
             String msg="";
             while((msg=input.readLine()) != null)
                System.out.println("From Client: "+msg);
          catch(IOException e)
          catch(Exception e)
    }Client:
    import java.net.*;
    import java.io.*;
    public class client
       static private Socket socket;
       static private DataInputStream input;
       static private PrintStream output;
       public static void main(String a[])
          try
    socket=new Socket("10.243.21.101",2000);
    System.out.println("\nconnected to: \""+socket.getInetAddress()+"\"");
             input=new DataInputStream(socket.getInputStream());
             output=new PrintStream(socket.getOutputStream());
             output.println("From Client(Tux): "+a[0]);
             String msg="";
             //while((msg=input.readLine()) != null)
                 System.out.println("From Server(Bill): "+msg);
          catch(java.io.IOException e)
          catch(Exception e)
    }

  • RTP Server/ Client Program using JMF Library

    Hi folks,
    I am trying to send A/V data from Camcorder(SONY DCR-PC115) to PC(Red Hat Linux 7.3 kernal version 2-18.3), and then send that data to clinet programm via a network ( i.e. A/V data should be delivered by network using RTP/RTCP Protocol).
    I guess I need to make RTP Server and RTP Client program, and using JMF library in order to send data with RTP Protocol. Isn't it?
    So what I want here is Do any body have idea/experiance in making RTP Clinet /Server program using JMF library then pls let me know
    my e-mail id is [email protected], [email protected]
    Many thanks
    looking forward to hear from you soon
    Regards
    Madhu Chundu

    Hi,
    I'm also working on the same type of problem, so if anyone has already worked or have an idea of how it works or does, please mail me the details to my mail-id: [email protected]
    Thanks In Advance,
    Rajanikanth Joshi

  • Server/Client Programs

    Can somebody give me advice on writing a program that a client reads from a text file and sends the data to a server which in turn does math operations or strign operations on the data .....then sends the new file back to the client to be displayed.Thanks

    Here is some code that implements a very rudimentary
    client/server relationship. import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Client extends JFrame implements ActionListener
         private JTextArea jta;
         private void init()
              addWindowListener(new WindowAdapter()     {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              setSize(300, 200);
              jta = new JTextArea(20, 40);
              JPanel jp = new JPanel(new FlowLayout());
              JButton jbOK = new JButton("OK");
              jbOK.addActionListener(this);
              jp.add(jbOK);
              JButton jbDone = new JButton("Done");
              jbDone.addActionListener(this);
              jp.add(jbDone);
              getContentPane().add(jp, BorderLayout.SOUTH);
              getContentPane().add(jta);
              show();
         void setData(String s)
              jta.setText(s);
         public void actionPerformed(ActionEvent ae)
              if (ae.getActionCommand().equals("Done")) {
                   System.exit(0);
    // Call your input routine here and pass the result to Server instead of the String from the JTextArea
              Server s = new Server(this, jta.getText());            
    s.compress();
         public static void main(String args[])
              Client c = new Client();
              c.init();
    class Server
         String s;
         Client c;
         public Server(Client passer, String pass)
              s = pass;
              c = passer;
         void compress()
              StringTokenizer st = new StringTokenizer(s);
              String n = "";
              while(st.hasMoreTokens()) {
                   n += st.nextToken();
              c.setData(n);
    }This should get you started.
    Mark

  • Server/Client program to work with a handheld windows device and a laptop

    Hi, I am trying to develop a program for work. I basically need to test the life of a handheld device by essentially having the device "ping" a server. I need the device (Client) to make a connection to the server, and if it works, I want it to write out to the server the time. Every thing that I have tried has failed, so far. I have experience with Java, but not a whole lot in Networking. I am still a student (and a lowly one at that). Can anyone help me with this? Should I use an applet? A socket? I'm not even really sure how to go about doing this.
    Thanks,
    Shawna

    Okay, the device is a scanning device used in warehouses. It has Windows CE 5. I'm trying to get in contact with the person that manages these handhelds to make sure that they support Java. Assuming they do, however, What do you believe is my best option? .Net was the preferred language, but I was having too much trouble trying to get Visual Studio on to my laptop computer, which I use for work, and I also don't have any experience using .Net. I tried creating Sockets, but I don't think I did it correctly. The only thing I have to go off of is an Introduction to Java book that I use for school, and the examples don't really help me for this situation. If I create sockets, do I need the client to have buttons to initiate the connection? How would I go about using a URL? I just need the server text pane to update every second letting me know that the handheld was able to connect to it, indicating that the battery hasn't died, yet. Later on, I would like to add some other information, but right now, I just need it to send that information. I can mess around with any modifications later on. Thanks for your help!

  • Yes, its another chat server/client program

    Im busy writing a chat program and am having a problem figuring out how to show the users that are online. The ChatServer class contains methods for recieving messages, broadcasting messages, accepting new connections etc.
    Im using non-blocking mode and I register all the connections with a Selector. When a new user connects to the server, I add the SocketChannel to a LinkedList which contains all the users that are online.
    My problem is that my ChatServer class runs completly seperatly from any other classes (I presume thats normal?). In other words, I run the ChatServer and once that is running I run the StartGUI class which creates the swing gui and all of that. I then type in the host name etc and connect to the server. So how would I show the users that are online? Even if I can somehow get all the ip addresses then ill figure out how to give 'nicks' and all that from there.
    As I said, I have a line (LinkedList.add(newChannel) which adds the clients to that list which I simply did so that i can display the number of users online. Is there a way I could now manipulate that LinkedList to get all the users and then display them (since it contains a list of all the SocketChannels)? Or would that not be possible?
    If it is possible to get the users from the LinkedList, then the other problem is the fact that the list is created as part of the ChatServer so I cant get to it?
    Another way that I thaught might be possible, is that since I register all the keys with a Selector when a new user is added (this happens in the ChatClient clas), then I might be able to get the users from that but im not sure if thats possible?
          readSelector = Selector.open();
          InetAddress addr = InetAddress.getByName(hostname);
          channel = SocketChannel.open(new InetSocketAddress(addr, PORT));
          channel.configureBlocking(false);
          channel.register(readSelector, SelectionKey.OP_READ, new StringBuffer());Ill add to my explanation if need be, since im very new to this sort of programming. Ill post some more code if need be.
    thanks, R

    Through some more playing around this afternoon ive figured out how im going to solve my problem. It may not be the best way to do it but I think that at least it is going to work.
    Im going to convert the LinkedList to a String and then change that into a ByteBuffer, and use channel.write(ByteBuffer) as if it was any other normal message.
    My logic will be as follows:
    Client: click 'get user list' button --> send String 'get users' to the server using channel.write("get users")
    Server: read the String like any other normal String 'channel.read(ByteBuffer) --> decode the ByteBuffer back into a String --> if the String sais "get users" --> put the LinkedList into a String and then into a ByteBuffer --> send the buffer using channel.write(buffer)
    Client: check the incoming buffer for some or other string (maybe an ip address) that will let it know that it is the list of users and not a normal string. Then use a bit of String manipulation to extract the IP addresses from the String.
    Is this a reasonable way of doing it? Any other ideas?
    Also,...Is it alright to add the linked list to a String and then into a ByteBuffer to send? Since if there are for example 100 users online then it will be quite a big string and therefore there will be a lot going into the buffer and being sent by the server. Are there any potential problems I could run into here with lots of users?
    (lol, its been great talking to myself here ;) , hopefully some of you will have some comments or ideas after the weekend.)
    R

  • Server / client program help

    Was hoping someone could give me advice on some coding im trying to do for uni.
    To give you an overall view: im trying to create a little inventory program where there is a server interface and a client interface. Now on the client interface it displays a menu with several options and the server interface displays whats in the repository. Upon choosing one of those options it sends the appropriate method request to the server handler. What im trying to do is add a function where i can dynamically add items to the repository. This is already in place from the code i have from uni using the server.put class and method. however i cant seem to add them to it
    I have botched together this method which i think will add new items to the repository:
    public String addItem(){
        String serialNo = (String) receive();
        String description = (String) receive();
        Integer stock = (Integer) receive();
        String location = (String) receive();
        //String dateTime = (String) receive();
        //creates new stockitem from stockitem class
        StockItem item = new StockItem(serialNo, description, stock, location) ;
        // creates new serial number
        serialNo = new Integer(server.getReposSize() + 1).toString();
        //Must make item code unique to this client
        serialNo = serialNo + this.hashCode();
        while (server.exists(serialNo)){
        serialNo = new Integer(server.getReposSize() + 1).toString();
    server.put(serialNo, item);
    return "Item added";
    }So above i hope the method will recieve the data input on the client interface and then use "server.put" to input the recieved data into the server repository and to display it in the server interface.
    Now on the client side i have added code to send the serialno, description,stock and location. Shown below:
    if (choice.equals("n")){
            //Add new Item
            send("addItem"); // remote method
            //Send Serial Number
            System.out.println("Item Serial no.\t");
            String serialNo = getString();
            send (new Integer(serialNo));
            // send description
            System.out.println("Item Description\t");
            String description = getString();
            send(new String(description));
            //Send No. of STock
            System.out.println("No. Of Stock\t");
            String stock = getString();
            send (new Integer(stock));
            // send Item Location
            System.out.println("Item Location\t");
            String location = getString();
            send(new String(location));
            send(getDateTime());         //Time of transaction
            System.out.println(receive());      //Find out the status of our command
            }So above should send this from the client interface to the server which should recieve it.
    But my problem is how do i insert the data sent by the user into the server repository? I thought this would work by using "server.put(serialNo, item);" in the first method shown but it doesnt seem to work?
    As you can see from the first "additem" method there is a "server.put" which relates to a method in the server class which adds things to the repository. ive looked in the server class and noticed the put method has only two objects. Originally i was trying to fit the 4 objects (serial description,location and stock) in there but as you can see from my first method i have tried inserting just two of these and they still dont show in the server interface.
    Here is the snappit from the server class:
    public synchronized void put(Object key,Object item){
        repos.put(key,item);
        hci.updateObjects(repos,locked);
        }Any idea's on this? SOrry if im vague im not too familar with the correct terminology im still getting the hang of it all! I have however statically defined some test items in my code and it shows in the server interface OK but when i send them dynamically they do not work.
    Thanks

    Any idea's? im stumped at the moment.

  • Server socket needs to sends images to applet

    Dear expert programmers
    I've got a simple socket server ruuning on my machine which accepts a connection from an applet on an arbitrary port.
    The problem I have is that it needs to "CONSTANTLY" take screenshots of the desktop and send them to the applet so that the applet can load them for people to see. It's a remote desktop project I've been working on for some time now and I have no idea on how to create images and send them using sockets to an applet.
    Could someone please help me - sample code would be appreciated - also efficiency of sending desktop scrrenshots isn't an issue for now.
    Many thanks

    ok, need to know what you have/can get working....
    have you got any working commuincation between Applet and server?
    could you write a method that converts int to 4 bytes?
    and use that to convert int[] to byte[] (4 times as big)?
    for the screen capture part..
    Robot robber=new Robot();
    BufferedImage bi=robber.createScreenCapture(new Rectangle(0,0,screenWidth,screenHeight));
    int[] pixels=bi.getRGB(0,0,screenWidth,screenHeight,null,0,screenWidth);
    byte[] data=toByteArray(pixels);get the outputStream from the connected Socket and use its write(byte[] b) method to send the data
    at the Applet, get the InputStream, use its read(byte[] b) method to get the data
    re-pack to int[] and use setRGB(0,0,screenWidth,screenHeight,int[] data,0,screenWidth)
    get the Graphics Object for the display element of the Applet you want to show the image and use drawImage(BufferedImage,0,0,null) to display

  • Server Client Program

    I want to write a server program to accept five clients to send integers to the server only and to accept other five clients to receive integers from the server only. I have got a big stick in here. Anyone can give me an idea?

    LackOfInformationException thrown by darkemprorer's original post, process terminated.
    Clarification of requirements required to help you with your problem.

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

  • Compiling server-client with eclipse

    hi. i'm new to java programming and i'm using eclipse. i have 2 simple programmes, one for a server and another for a client and would like to use them to communicate with each other. i have an error message with both programs.. i think that there is a prblem with my server program...is there anything i need to add to get it running or is there anything in particular needed when using eclipse to run server/client programs? here is the code:
    import java.io.*;
    import java.net.*;
    public class Serveur {
         public static void main(String[] args) {
              try{
              ServerSocket ss= new ServerSocket(1500);
              Socket sc= ss.accept();
              System.out.println("connection etablie");
              PrintWriter flux_sortant = new PrintWriter(sc.getOutputStream());
              flux_sortant.println("coucou j'ecris");
              //ss.close();
              //sc.close();
              catch (IOException e){
                   System.out.println("Connection non etablie");
    and for the client:
    import java.io.*;
    import java.net.*;
    public class Client {
         public static void main(String[] args) {
              try{
                   Socket s= new Socket("local host",1500);
                   BufferedReader flux_entrant= new BufferedReader(new InputStreamReader(s.getInputStream()));
                   System.out.println("J'ai lu:" + flux_entrant.readLine());
              catch (IOException e){
                   System.out.println("probleme de connection");
    thanks

    Hello,
    if you want your server programm to listen for incoming connections all the time, then you shouldn't close your ServerSocket because it is accepting the connections.
    I would try something like this:
    public class Serveur implements Runnable{
           private boolean running = true;
           private ServerSocket ss;
           public Serveur(){
                   ss = new ServerSocket(1500);
          public static void main(String[] args){
                  new Thread(new Serveur()).start();
        public void run(){
                while(running){
                        Socket sc = ss.accept();
                        System.out.println("Connection established");
                       PrintWriter writer = new PrintWriter(sc.getOutputStream());    
                       writer.println("Blah");
                       sc.close();           
    }This server would accept a connection send back "Blah" and close the connection to the client.
    hope that helps...
    greetz
    Message was edited by:
    n3bul4

  • Send Images from CVS-1450 to host

    How is the better way to retrieve the acquired images from CVS when I realize an host application?
    Is the VI-Server the better solution?
    Anyone has some examples?
    Thanks

    Have a look at the following example on www.ni.com :
    Compress IMAQ Images to JPEG Streams for Faster Transfer
    http://sine.ni.com/apps/we/niepd_web_display.DISPLAY_EPD4?p_guid=B45EACE3E88
    D56A4E034080020E74861&p_node=DZ52507&p_submitted=N&p_rank=&p_answer=&p_sourc
    e=External
    CVS side :
    You acquire the images, compress the images, then use a TCP server in order
    to send images to the host.
    Host side:
    Use a TCP client to retrieve the images.
    Jean-Christophe BENOIT
    Alliance Vision
    "FABIOSIEMENS" wrote in message
    news:[email protected]..
    > How is the better way to retrieve the acquired images from CVS when I
    > realize an host application?
    > Is the VI-Server the better solution?
    > Anyone has some exam
    ples?
    > Thanks

  • Help required in sending images to client

    I have a java program that take snapshots of my screen at say 10 pics per second now i want these pics to be sent to another computer in the same order....
    i tried to achieve this but i am able to send only 1 image i think the first image.......... heres my code ...
    Server code..........
    import java.awt.*;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle; 
    import java.awt.Robot;  
    import java.awt.image.BufferedImage; 
    import javax.swing.JFrame;
    import java.net.*;
    import javax.imageio.*;
    import java.util.*;
    import java.io.*;
    public class VideoServer extends JFrame
          BufferedImage img; 
          Robot robot; 
          Rectangle rect; 
          public static void main(String args[])
           new VideoServer();
          public VideoServer()
          //init components 
           try
               robot = new Robot(); 
               rect = new Rectangle(200,200,300,300); 
         catch (AWTException e)
                e.printStackTrace();
           this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
           this.setSize(500,500); 
         //  this.setVisible(true);
           takeShots(); 
          private void takeShots()
           try
               ServerSocket s=new ServerSocket(8189);
               Socket incoming=s.accept();
               try
                OutputStream os=incoming.getOutputStream();
                for (int i = 0;i<100 ; i++)
                    img = robot.createScreenCapture(rect); 
                //repaint();
                    ImageIO.write(img,"jpg",os);
                    if(img==null)
                     System.out.println("NULL");
                    try
                     Thread.sleep(50);
                    catch (InterruptedException e)
                     e.printStackTrace();
               finally
                s.close();
           catch(IOException e1)
        /*  public void paintComponent(Graphics g)
           super.paintComponents(g);
           //Graphics2D g2 = (Graphics2D)g;
           //g2.drawImage(img,0,0,this);
    }and heres my client program
    import java.util.*;
    import java.io.*;
    import java.net.*;
    import java.awt.image.*;
    import javax.imageio.*;
    public class ImageClient
        public static void main(String args[])
           ArrayList list=new ArrayList(100);
           BufferedImage tmp=new BufferedImage(400,400,BufferedImage.TYPE_INT_RGB);
         try
             Socket s=new Socket("127.0.0.1",8189);
             try
              InputStream in=s.getInputStream();
              for(int i=0;i<100;i++)
                  tmp=ImageIO.read(in);
                  list.add(tmp);
             finally
              s.close();
         catch(IOException e)
             e.printStackTrace();
         try
             for(int i=0;i<100;i++)
              tmp=(BufferedImage)list.get(i);
              ImageIO.write(tmp,"jpg",new File("/home/gaurav/java programs/Formedimages/created"+i+".jpg"));
         catch(Exception exp)
             System.out.println("hello5");
    }

    It's been a while, but I know you can write a series of images to a file, then later read back that series of images. Why don't you work on doing this with file i/o first (easier to debug, and you can examine the file with standard image viewers), before sprinkling sockets on it?

  • How can my client program call program located at server?

    Hi All,
    I have a client-server application. How can my client program call program located at server?
    At the beginning my program works as long as RSA Agentinstalled at client. So my program only call rsa library and communicate with RSA Agentby passing userid and passcode. Once RSA Agent receive it will send to RSA Managers to validate.
    But now my user want the RSA Agent installed in my Server. I wondering how to do that as the library given will only detect local RSA Agent. So I'm thinking to separte the library and create new project. Then in this project as a medium to pass userid and passcode. This project I will compile and allocate to server. Then my programs will call the new program i created by passing userid and passcode. I wondering can I do that?
    Thanks in advance.
    Regards,
    Azli

    Why not take the tutorial first? [http://java.sun.com/javaee/5/docs/tutorial/doc/JavaEETutorial.pdf]

Maybe you are looking for

  • How can I execute a command after kernel-upgrade/mkinitcpio

    Because of the archlinux specific kernelnaming-policy there's a problem when using grub2. The created menu looks nasty because grub-mkconfig can't find the proper kernel-version. (Bugreport: https://bugs.archlinux.org/task/25453) Even if this is fixe

  • Iso 7 update has lost my notes

    i have recently updated my iphone 4s to the iso 7 and have lost my notes ....how do i get this back pls help...

  • E-Commerce Gateway Question about Interface File Definition.

    Hello Gurus, Does anyone know if Oracle e-Commerce Gateway (11.5.10.2) deliver the Interface File Definition for Inbound Purchase Orders (850/ORDERS) - _'IN: Purchase Orders (850/ORDERS)'_ out of the box? I see Interface File Definition for OPM Purch

  • Best way to report on Computer Usage

    Is there any magic report that will tell me if machines are NOT being utilized? I know you can do Software metering for Apps, but I just need to know if a machine is being used or not.   I read where you can do powermanagement reports, but I'm not su

  • BEx Authorisation: ODS objects

    Hi, RS_COMP only has a line for specifying authorisation for InfoCubes. Is there not an equivalent for ODS objects. RS_ODSO does not provide the same nature of authorisation. Any idea? Regards, Lea