Send Object with socket

hi,
I have defined objects which correspond to my messages, those object have only "byte" attributes and are realizable, exemple
     private byte[]      source;
     private byte[]      destination=new byte[2];
     private byte[]      n_emetteur=new byte[2];
     private byte[]      n_message=new byte[2]; ...................
my problem is when i send and object by in.writeObject(myObject) i can't read it in the other hand, because my client is written with C language and i recieve only the name of my class package.package.myclass.
can you help my find out best way to send my objects and be compatible with any client?
thank's

tmazight wrote:
i post this after a large search on google, and how can google get its content if peaple can't post on forums!!!!That's your biggest problem right there: you seem to have the strange idea that the answer must come from a forum; even Google must find the answer there, like there is nothing else but a forum to find answers in. But no, it doesn't work that way. Where did those people you expect to spit out the solution get their knowledge from huh?
1) books
2) articles
3) courses (for example by going to school)
4) experimentation
5) thought
I'm pretty sure that in stead of having this need to get an answer from a forum you would in fact sit down and think about it, you will manage to solve it yourself. If you can't then I'm afraid that even your basic knowledge if Java is severely lacking and you simply need to brush up on Java using a good book.
Start by following the hint EJP already gave you. Apparently you have some client which expects data in a very specific way which is throwing up all these boundaries that you can't seem to be able to break. HOW is that client expecting it to be? And I'm talking about specifics. Its all bytes, in what way does the client expect the bytes to be. Given that starting point, how would you be able to take what you know about Java (which will really boil down to working with primitives in stead of objects) get you to provide the information in such a way that it is how the client can work with it?
If you require further assistance you'll have to minimally give an example of the specifications - how does the client expect the bytes. Perhaps then someone can provide you with an example of how to produce something like that using Java code.
See how that works? You do something, someone else can do something back for you. That's the only way it is going to work.

Similar Messages

  • Sending objects with sockets (and making a mess thereof)

    I'm playing about with client/server interaction and have made a simple program where a server waits for a connection on its given port, accepts a socket connection and every second checks for any input from the client and sends a Point object with co-ordinates to the client
    The client in renders the Point object and every second checks for an updated Point from the server, whenever the left or right arrow keys are used the server is sent the keyevent object to process and change the co-ordinates of the point which will then be sent back
    But it doesn't work, the server thread hangs on the if statement testing for a new object to read. If the code looking for a new object is comented out, the system works perfectly (with the random co-ordinates shown, the Point object itself is held in another class and would be used if the server could read the input)
              try
                   ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
                       ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
                       boolean temp = true;
                       while (temp == true)
                        sleep(1000);
                        Object o = in.readObject();
                        if (in.readObject() != null)
                             parent.process.updatePoint((KeyEvent)in.readObject());
                        out.writeObject(new Point((int)(Math.random() * 200), (int)(Math.random() * 200)));
              } Could anyone advise me why it specifically doesn't work? Having said that I realise my design is probably rather inefficient and generally poor and any general tips are welcome to
    Any help appreciated

    I think we are going to need to see the other side of your program. If your code hangs at the if statement:
                        if (in.readObject() != null)
                             parent.process.updatePoint((KeyEvent)in.readObject());
                        }Then i would have to assume the object is never recieved.

  • Send Object With a Note

    Hi
    When selecting 'Send object with a note' from a purchase order and clicking on the 'Attributes' tab the Sensitivity is set to '502 Confidential'.  Can you please advise how to change the sensitivity to '501 Standard'?
    Thanks

    Hi all,
    I have found the solution for it.
    Share with you.
    Inside Function Group:CRM_1O_UI
    Include LCRM_1O_UIF17
    for the 'is_disabled' field control the status of the corresponding fcode.
    Update following code:
    {   INSERT         xxxxx                                      1
    if sy-cprog = 'SAPMCIC0'.
        CALL METHOD toolbar_create_process0->add_button
          EXPORTING
            fcode       = lv_fcode
            icon        = lv_icon
            butn_type   = lv_type
            text        = lv_text
            quickinfo   = lv_tip
            is_disabled = 'X'.
    else.
    *}   INSERT
        CALL METHOD toolbar_create_process0->add_button
          EXPORTING
            fcode       = lv_fcode
            icon        = lv_icon
            butn_type   = lv_type
            text        = lv_text
            quickinfo   = lv_tip
            is_disabled = ' '.
    *{   INSERT         xxxxx                                       2
    endif.
    *}   INSERT

  • How to redefine GOS toolbar function "SEND OBJECT WITH NOTE" for deliveries

    Hello Abapers,
    for inbound and outbound deliveries (tcodes VL01N, VL02N, VL03N, VL31N, VL32N, VL33N) I have to replace the GOS toolbar function SEND OBJECT WITH NOTE with a redefined function matching the following specifications:
    - Title field needs a different content
    - Text (note content) should be filled by default, maybe with standard text, but can be overwritten
    - All attachments in the attachment list of the object should be included by default or be selectable thru an additional button
    Also possible could be an addiitonal toolbar function SEND ATTACHMENTS WITH NOTE as a copy of SEND OBJECT WITH NOTE.
    Although I checked the SDN forums for a matching solution, I couldn't find one in tons of GOS threads.
    Perhaps someone had solved a similar problem to send obejct with notes from GOS toolbar with several of the object's attachments.
    Maybe some GOS classes have to be redefined for that, but this should only be available for deliveries, not for the other BOR types.
    I'm waiting for your ideas.
    Best regards,
    Klaus
    Edited by: Klaus Babl on Feb 16, 2012 10:13 AM

    No the list of steps done to solve the issue:
    1. Copy of class CL_GOS_SRV_SEND_OBJECT to new class /SIE/IS_BSD_GOS_SRV_SEND_ATT.
    2. SM30 for table SGOSATTR: New entry for new service ZSO_SENDATT for the new class.
    3. Copy of methods ON_SERVICE_SUCCEEDED, CHECK_STATUS, CREATE_ROOT_ITEM and ON_LINK_CREATED from class CL_GOS_SRV_ATTACHMENT_LIST to the new class.
    4. New code added to the top of method CHECK_STATUS to show the service for deliveries only:
    IF  is_lporb-typeid  NE  'BUS2015'
    AND is_lporb-typeid  NE  'LIKP'.  
        ep_status = mp_status_invisible.
        EXIT.
    ENDIF.
    5. Copy of function group SAPLSGOS_OUTBOX and function module SGOS_SEND_OBJECT_WITH_NOTE to own copies.
    6. Before calling cl_bcs=>short_message  there are several steps to do:
    - CALL METHOD cl_binary_relation=>read_links
    - CALL FUNCTION 'SO_DOCUMENT_READ_API1' for all links
    - cl_document_bcs=>create_document for all those documents (we are using types ATTA, NOTE and URL)
    - APPEND those created documents to the attachment table and pass it to i_attachments of cl_bcs=>short_message
    Solved issue!
    COMMENT: This SDN wiki document is outdated and doesn't work any more:
    http://wiki.sdn.sap.com/wiki/display/Snippets/ABAP-SendingGOSattachmentstoanemailaddress
    Best regards,
    Klaus

  • How to setup Send Object With Note

    Hi all,
    I was trying to send a message to external email.
    So, for eg, in ME23N, I click on this "Send object with note" to a address which is type U.
    And in SCOT, business object is send as htm file type.
    However, when I receive this mail that i send, there is no url being generated.
    Below is the content of the email:
    If you are not forwarded automatically, use the following link:
    If the link is not to a valid server, log on to the SAP system and check the following object:
    System:     DEV
    Client:     123
    BOR Object Type:     BUS2012
    BOR Object Key:     4000000001
    Which setting am I missing?
    FYI, I'm using ECC 6. Extended notification has been setup.
    Thanks
    Edited by: Jack Wong on Jan 24, 2008 5:07 AM

    Hi Martin,
    Thanks for your reply.
    However, I don't think it's because of the mail server deleted the attachment.
    The htm file is attached to my external mail.
    And the htm file said that it will forward me to the link.
    I'm wondering which setting am I missing.
    Thanks.

  • Sending object over socket - please help (urgent)

    I have written a server/client application where server sends object to client.
    But on the client I've received the first message "@Line 1: Get ready!!!" TWICE but NEVER the second message "@Line 2: Please input Start".
    Please help me! Its urgent! I appreciate my much in advance.
    The source for Server:
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import sendNode;
    public class TestSer {
         static sendNode sendNodeObj = new sendNode();
    static String inputLine;
         public static void main(String[] args) throws IOException {
    ServerSocket serverSocket = null;
    try {
    serverSocket = new ServerSocket(4444);
    } catch (IOException e) {
    System.err.println("Could not listen on port: 4444.");
    System.exit(1);
    Socket clientSocket = null;
    try {
    clientSocket = serverSocket.accept();
    } catch (IOException e) {
    System.err.println("Accept failed.");
    System.exit(1);
    OutputStream o = clientSocket.getOutputStream();
    ObjectOutput out=new ObjectOutputStream(o);
    BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        clientSocket.getInputStream()));
    sendNodeObj.sendMsg="@Line 1: Get ready!!!";
    sendNodeObj.typeNode=-1;
    out.writeObject(sendNodeObj);
    out.flush();
    sendNodeObj.sendMsg="@Line 2: Please input Start";
    sendNodeObj.typeNode=-2;
    out.writeObject(sendNodeObj);
    out.flush();
    inputLine = in.readLine();
    while (!inputLine.equalsIgnoreCase("Start")) {
         sendNodeObj.sendMsg="@Error, Please input Start";
    sendNodeObj.typeNode=-1;
    out.writeObject(sendNodeObj);
    out.flush();
    inputLine = in.readLine();
    out.close();
    in.close();
    clientSocket.close();
    serverSocket.close();
    The source code for Client :
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.applet.Applet;
    import sendNode;
    public class TestCli extends Applet {
    static sendNode recNodeObj=null;
    public static void main(String[] args) throws IOException {
    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
    Socket kkSocket = null;
    PrintWriter out = null;
    try {
    kkSocket = new Socket("127.0.0.1", 4444);
    out = new PrintWriter(kkSocket.getOutputStream(), true);
    } catch (UnknownHostException e) {
    System.err.println("Don't know about host.");
    System.exit(1);
    } catch (IOException e) {
    System.err.println("Couldn't get I/O for the connection to: taranis.");
    System.exit(1);
    InputStream i= kkSocket.getInputStream();
    ObjectInput in= new ObjectInputStream(i);
    try {
         recNodeObj = (sendNode)in.readObject();
    System.out.println(recNodeObj.sendMsg);
         recNodeObj = (sendNode)in.readObject();
    System.out.println(recNodeObj.sendMsg);
    if (recNodeObj.sendMsg.equalsIgnoreCase("@Line 2: Please input Start")) {
    out.println("Start");
    } catch (Exception e) {
    System.out.println(e.getMessage());
    System.out.println("receive error.");
    System.exit(1);
    out.close();
    in.close();
    stdIn.close();
    kkSocket.close();
    The object to be sent:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    class sendNode implements Serializable {
    String sendMsg;
    int typeNode; // -1 no ObjectNode;
    // 1 right node, 2 base node, 3 left node;
    Object objectNode;

    You forgot to reset the OOS. ObjetOutputStream keeps a buffer of objects, so if you write the same object again with changes on it, you must reset the buffer.
    out.writeObject(sendNodeObj);
    out.flush();
    out.reset();

  • Error by submitting objects with socket

    Hallo,
    I allways get the following error massage:
    Error:
    java.net.ConnectException: Connection timed out: connect
    Exception in thread "Thread-0" java.lang.NullPointerException
    at com.Receiver.read(Receiver.java:36)
    at Input.write(Kommunicator.java:111)
    at Input.run(Kommunicator.java:137)
    Error:
    java.net.ConnectException: Connection timed out: connect
    Here is my code:
    import com.*;
    import TerminalIO.*;
    import java.util.*;
    import java.io.*;
    import java.net.*;
    public class Kommunicator
         public static void main(String [] args){
              KeyboardReader inread = new KeyboardReader();
              int port = inread.readInt();
              String ip =inread.readLine();
              Emitter out = new Emitter(ip, port);
              Input in= new Input(new Receiver(ip, port));
              try{
                   in.start();
                   boolean flag=true;
                   while(flag){
                        out.open();
                        if(line.equalsIgnoreCase("\\quit")){
                             out.write("User left");
                             in.interrupt();
                             flag=false;
                        else{
                             out.write(line);
                        out.close();
              catch(IOException e){
                   System.out.println("Error:\n"+e.toString());
    class Input extends Thread
         private Receiver out;
         public Input(Receiver a){out=a;}
         private void open(){
              try{
                   out.open();
                   super.start();
              catch(IOException e)
                   System.out.println("Error:\n"+e.toString());
         private void close(){
              try{
                   out.close();
              catch(IOException e)
                   System.out.println("Error:\n"+e.toString());
         private void write(){
              try{
                   Object temp=out.read();
                   if(!temp.equals(null))
                        String line=temp.toString();
                        do
                        System.out.println("Other:"+line);
                        line=out.read().toString();
                        }while(!line.equals(""));
              catch(IOException e)
                   System.out.println("Error:\n"+e.toString());
              catch(ClassNotFoundException e)
                   System.out.println("Error:\n"+e.toString());
         public void run()
              open();
              write();
              close();
    package com;
    import java.net.*;
    import java.io.*;
    public class Receiver
         private String ip;
         private int port;
         private ObjectInputStream ois;
         private Socket sock;
         public Receiver(String a, int b)
              ip=a;
              port=b;
         public void open() throws IOException
              sock = new Socket(InetAddress.getByName(ip), port);
              ois = new ObjectInputStream(sock.getInputStream());
              sock.setSoTimeout(3000);
         public void close() throws IOException
              ois.close();
              sock.close();
         public Object read() throws IOException,ClassNotFoundException
              Object temp=null;
              temp=ois.readObject();
              return temp;
         public int getPort()
         {return port;}
         public String getIp()
         {return ip;}
    package com;
    import java.io.*;
    import java.net.*;
    public class Emitter
         private String ip;
         private int port;
         private Socket sock;
         private ObjectOutputStream oos;
         public Emitter(String a, int b)
              ip=a;
              port=b;
         public String getIp()
         {return ip;}
         public int getPort()
         {return port;}
         public void open() throws IOException
              sock = new Socket(InetAddress.getByName(ip),port);
              oos =new ObjectOutputStream(sock.getOutputStream());
              sock.setSoTimeout(3000);
         public void write(Object a) throws IOException
         {oos.writeObject(a);}
         public void close() throws IOException
              oos.close();
              sock.close();
    }I hope you can help me with my problem and I hope you can answer my questions;
    1) is it a general problem with socket, that it is not allowed to submit objects on a permanent way?
    2) is it there another way how to submit object?
    3) can the problem be caused through trying to submit packeges in a lan?

    1. When you get an exception trying to construct any object, it is poor practice to print and ignore it.
    2. It is invalid to continue as though the object had been constructed.
    3. In this case you failed to connect but then continued to the read method using a null socket reference.
    4. You need to restructure your code so that it reacts correctly to exceptions.
    5. Then you need to solve the question of why the connect failed.

  • Sending objects over sockets - issues i am having

    Hi, this is my first time posting on these forums and I have exhausted my mental capacity on this problem i have been having the past few days. Hopefully somone could help me out.
    I am doing a uni project, and the goal i am currently trying to achieve is to send an object (serialized) from a client to a server. I will atach the code i have written and i will explain more from there.
    This is the server (part of the class, which calls this method)
    Constructor:
      public Broker(String bID) throws Exception {
        brokerID = bID;
        bServer = new ServerSocket(Integer.parseInt(bID));
        System.out.println("Broker listening on port " + bID);
        this.start();
    Main method
      public static void main(String[] args) throws Exception {
        new Broker("8008");
    run method
      public void run() {
        while(true) {
          try {
            Socket bSocket = bServer.accept();
            System.out.println("Accepted a connection from: " + bSocket.getInetAddress());
            brokerServer(bSocket);
            bSocket.close();
            System.out.println("Connection closed");
          catch (Exception e) { e.printStackTrace(); }
    Broker Server
      public void brokerServer(Socket bSocket) {
        BufferedReader in = null;
        ObjectOutputStream oos = null;
        PrintWriter out = null;
        ObjectInputStream ois = null;
        try {
          while (true) {
            oos = new ObjectOutputStream(new DataOutputStream(bSocket.getOutputStream()));
            out = new PrintWriter(new OutputStreamWriter(bSocket.getOutputStream()));
            ois = new ObjectInputStream(bSocket.getInputStream());
            in = new BufferedReader(new InputStreamReader(bSocket.getInputStream()));
            out.println("Connection with Broker on port " + brokerID + " established");
            out.flush();
            //read in first line
            String str = in.readLine();
            //if lineis null, break while loop
            if (str == null)  break;
            else {
              //a request is recieved from user to get user certificate
              if (str.trim().equals("GETUSERCERT")) {
                //read in the userName, size of paywords and user publick key (used in certificate)
                String userName = in.readLine();
                String size = in.readLine();
                PublicKey userPk = (PublicKey) ois.readObject();
                //generate user certificate
                UserCertificate uc = generateUserCertificate(userName, userPk, Integer.parseInt(size, 10));
                //send text to user stating next message is user certififcate
                out.println("SENDUSERCERT");
                out.flush();
                //user Certificate
                oos.writeObject( (UserCertificate) uc);
                oos.flush();
                break;
              if (str.trim().equals("FINISH"))
                break;
            ois.close();
            oos.close();
            out.close();
            in.close();
        catch(Exception e) { e.printStackTrace(); }
    This is the client
      private void requestUserCertificate(int sizeOfPaywordChain, String BrokerID) {
        String host = "localhost";
        ObjectOutputStream oos = null;
        ObjectInputStream ois = null;
        PrintWriter out = null;
        BufferedReader in = null;
        Socket u2bSocket = null;
        try {
          u2bSocket = new Socket(host, Integer.parseInt(BrokerID));
          System.out.println("Connecting to Broker on port " + BrokerID);
          ois = new ObjectInputStream(new DataInputStream(u2bSocket.getInputStream()));
          oos = new ObjectOutputStream(u2bSocket.getOutputStream());
          out = new PrintWriter(new OutputStreamWriter(u2bSocket.getOutputStream()));
          in = new BufferedReader(new InputStreamReader(u2bSocket.getInputStream()));
          //Informs broker that a user certificate is being requested
          out.println("GETUSERCERT");
          //send to broker, username and size of payword chain
          out.println(userName);
          out.println(sizeOfPaywordChain);
          out.flush();
          //send user's public key accross
          oos.writeObject((PublicKey) userPublicKey);
          oos.flush();
          out.println("FINISH");
          out.flush();
          //wait for response
          while(true) {
            //read in line
            String str = in.readLine();
            //if line is null, break while loop
            if (str == null) break;
            //if line read is "SENDUSERCERT" then next line is userCertificate sent from Broker
            if (str.trim().equals("SENDUSERCERT")) {
              //read User Certificate
              userCert = (UserCertificate)ois.readObject();
              break;
            else System.out.println(str);
          //close connections and streams
          u2bSocket.close();
          ois.close();
          oos.close();
          out.close();
          in.close();
        catch (Exception e) { e.printStackTrace(); }
      }I will be regurarly checking this thread, so any other code which you think i should post i will, i can post is ASAP.
    The problem
    First time i run the programs, it works perfectly, however when i run the client program again, it shows this error
    java.io.EOFException
         at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2438)
         at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1245)
         at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
         at User.requestUserCertificate(User.java:75)
         at User.main(User.java:278)the broker server doesn't display anything.
    Would anyone have any idea whats going on??
    Sometimes when i run it, it might display the above error, or it might work. its about 50/50. I have read heaps of similar problems people have had and posted on this forum, but i still don't have any luck in solving this delema.
    Any kind of help will be greatly appreciated.
    Rish

    I see one problem with the code. You are opening both ObjectInputStream ois and a BufferedReader in on the same socket. This won't work as "in" will read ahead to fill up its buffer. This could cause "ois" to find the socket already at end of stream prematurely. I would only use the Object Streams and send the strings as objects.

  • Send Object through Socket

    Hi,
    I am trying to send an object from Server to Client but the ObjectInputStream.readObject() on the client blocks.
    net beans Project can be found Here .
    Why it doesn't work?
    Thanks,
    Itay

    The Server works fine... it waits for a second client after the first one get connected
    I will post here the code.
    Server Code
    public class MemoryServer
        private final static int DEFAULT_BOARD_SIZE = 4;
        private ServerSocket socket;
         * Starting the server
         * @param n integer to determine the size of the board (must be even) the board will be n*n.
         * @param port the port on which the server will listen for incoming requests
        public void startServer(int n, int port)
            try
                socket = new ServerSocket(port);
            catch (IOException e)
                e.printStackTrace();
                System.exit(1);
            while(true)
                System.out.println("Listening on port " + port);
                Socket firstPlayerSocket = null, secondPlayerSocket = null;
                try
                    firstPlayerSocket = socket.accept();
                    System.out.println("First Player Socket Open: " + firstPlayerSocket.getInetAddress() + ":" + firstPlayerSocket.getPort());
                    MemoryGame game = new MemoryGame(n, firstPlayerSocket);
                    secondPlayerSocket = socket.accept();
                    System.out.println("Second Player Socket Open: " + secondPlayerSocket.getInetAddress() + ":" + secondPlayerSocket.getPort());
                    game.setSecondPlayer(secondPlayerSocket);
                    game.start();
                catch (IOException e1)
                    try
                        e1.printStackTrace();
                        if (firstPlayerSocket != null)
                            firstPlayerSocket.close();
                        if (secondPlayerSocket != null)
                            secondPlayerSocket.close();
                    catch (IOException e2)
                        e2.printStackTrace();
    public class MemoryGame extends Thread
        private Socket firstPlayerSocket, secondPlayerSocket;
        private ObjectOutputStream firstPlayerOut, secondPlayerOut;
        private ObjectInputStream firstPlayerIn, secondPlayerIn;
        private int boardSize;
        public MemoryGame(int boardSize, Socket firstPlayer) throws IOException
            this.boardSize = boardSize;
            firstPlayerSocket = firstPlayer;
            firstPlayerOut = new ObjectOutputStream(firstPlayerSocket.getOutputStream());
            firstPlayerOut.flush();
            firstPlayerIn = new ObjectInputStream(firstPlayerSocket.getInputStream());
            TextMessage message = new TextMessage("Waiting for opponent.");  //TextMesaage extends Message which implements Serializable
            firstPlayerOut.writeObject(message);
            firstPlayerOut.flush();
        public void setSecondPlayer(Socket secondPlayer) throws IOException
            try
                secondPlayerSocket = secondPlayer;
                secondPlayerOut = new ObjectOutputStream(secondPlayerSocket.getOutputStream());
                secondPlayerOut.flush();
                secondPlayerIn = new ObjectInputStream(secondPlayerSocket.getInputStream());
                TextMessage message = new TextMessage(Constants.GAME_START_MESSAGE);
                firstPlayerOut.writeObject(message);
                firstPlayerOut.writeObject(message);
            catch(IOException e)
                firstPlayerIn.close();
                firstPlayerOut.close();
                if (secondPlayerIn != null)
                    secondPlayerIn.close();
                if (secondPlayerOut != null)
                    secondPlayerOut.close();
                throw e;
        @Override
        public void start()
            endGame();
        private void endGame()
            try
                firstPlayerIn.close();
                firstPlayerOut.close();
                firstPlayerSocket.close();
                secondPlayerIn.close();
                secondPlayerOut.close();
                secondPlayerSocket.close();
            catch (IOException e)
                e.printStackTrace();
    }Client Code
    public class MemoryClient
        private Socket socket;
        public MemoryClient(String host, int port)
            try
                socket = new Socket(host, port);
                ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
                System.out.println("Connected to " + host + ":" + port);
                while (true)
                    try
                        Message msg = (Message)in.readObject();
                        System.out.println("Recieved");
                        if (msg instanceof TextMessage)
                            TextMessage textMsg = (TextMessage)msg;
                            if (!textMsg.getText().equals(Constants.GAME_START_MESSAGE))
                                System.out.println(textMsg.getText());
                                break;
                            MemoryFrame gameFrame = new MemoryFrame(socket);
                            gameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    catch(Exception e)
                        e.printStackTrace();
            catch (IOException e)
                e.printStackTrace();
                System.exit(1);
    }

  • Unable to send .mp3 with sockets, help!

    I need to send my .mp3 files throw a server but it stays in stuck in out.write(lenght), any suggestions for another type of way to do this...
    Other files are sent fine, .pdf, .txt, .doc... i might be the size but how to solve it...
    try {
                Socket socket=null;                 
                socket = new Socket(GlobalValues.ipOut, GlobalValues.portOut);
                OutputStream out = socket.getOutputStream();     
                InputStream fis = new FileInputStream(f);
                int length=0;
                BufferedInputStream buf = new BufferedInputStream(fis);
                //byte[] buffer = new byte[9*9*1024];
                GlobalValues.creatTextArea("                 Uploading PLEASE WAIT...", 1, Color.red, 0); 
                while((length = buf.read()) != -1){
                    out.write(length);
                    out.flush();
                GlobalValues.creatTextArea("                  FINISHED upload", 1, Color.green, 0);             
                fis.close();
                out.close();
            catch(Exception e){
                e.printStackTrace();
            }

    OutputStream out = socket.getOutputStream();     OutputStream out = new BufferedOutputStream(socket.getOutputStream());
    int length=0;This is not a correct name for this variable. You are reading bytes from the input stream, not lengths. A better name would be 'data'.
    while((length = buf.read()) != -1){
    out.write(length);
    out.flush();Move this flush to after the loop.
    If you're blocking in the write() it means the reader is slow reading. Using the BufferedOutputStream may fix this.

  • Cannot send and read objects through sockets

    I have these 4 classes to send objects through sockets. Message and Respond classes are just for
    trials. I use their objects to send ıver the network. I do not get any compile time error or runtime error but
    the code just does not send the objects. I used object input and output streams to send and read objects
    in server (SOTServer) and in the client (SOTC) classes. When I execevute the server and client I can see
    that the clients can connect to the server but they cannot send any objects allthough I wrote them inside the main method of client class. This code stops in the run() method but I could not find out why it
    does do that. Run the program by creating 4 four classes.
    Message.java
    Respond.java
    SOTC.java
    SOTServer.java
    Then execute server and then one or more clients to see what is going on.
    Any ideas will be appreciated
    thanks.
    ASAP pls
    //***********************************Message class**********************
    import java.io.Serializable;
    public class Message implements Serializable
    private String chat;
    private int client;
    public Message(String s,int c)
    client=c;
    chat=s;
    public Message()
    client=0;
    chat="aaaaa";
    public int getClient()
    return client;
    public String getChat()
    return chat;
    //*******************************respond class*****************************
    import java.io.Serializable;
    public class Respond implements Serializable
    private int toClient;
    private String s;
    public Respond()
    public Respond(String s)
    this.s=s;
    public int gettoClient()
    return toClient;
    public String getMessage()
    return s;
    //***********************************SOTServer*********************
    import java.io.*;
    import java.net.*;
    import java.util.Vector;
    //private class
    class ClientWorker extends Thread
    private Socket client;
    private ObjectInputStream objectinputstream;
    private ObjectOutputStream objectoutputstream;
    private SOTServer server;
    ClientWorker(Socket socket, SOTServer ser)
    client = socket;
    server = ser;
    System.out.println ("new client connected");
    try
    objectinputstream=new ObjectInputStream(client.getInputStream());
    objectoutputstream=new ObjectOutputStream(client.getOutputStream());
    catch(Exception e){}
    public void sendToClient(Respond s)
    try
    objectoutputstream.writeObject(s);
    objectoutputstream.flush();
    catch(IOException e)
    e.printStackTrace();
    public void run()
    do
    Message fromClient;
    try
    fromClient =(Message) objectinputstream.readObject();
    System.out.println (fromClient.getChat());
    Respond r=new Respond();
    server.sendMessageToAllClients(r);
    System.out.println ("send all completed");
    catch(ClassNotFoundException e){e.printStackTrace();}
    catch(IOException ioexception1)
    ioexception1.printStackTrace();
    break;
    Respond k=new Respond();
    sendToClient(k);
    }while(true);
    public class SOTServer
    ServerSocket server;
    Vector clients;
    public static void main(String args[]) throws IOException
    SOTServer sotserver = new SOTServer();
    sotserver.listenSocket();
    SOTServer()
    clients = new Vector();
    System.out.println ("Server created");
    public void sendMessageToAllClients(Respond str)
    System.out.println ("sendToallclient");
    ClientWorker client;
    for (int i = 0; i < clients.size(); i++)
    client = (ClientWorker) (clients.elementAt(i));
    client.sendToClient(str);
    public void listenSocket()
    try
    System.out.println ("listening socket");
    server = new ServerSocket(4444, 6);
    catch(IOException ioexception)
    ioexception.printStackTrace();
    do
    try
    ClientWorker clientworker=new ClientWorker(server.accept(), this);
    clients.add(clientworker);
    clientworker.start();
    catch(IOException ioexception1)
    ioexception1.printStackTrace();
    while(true);
    protected void finalize()
    try
    server.close();
    catch(IOException ioexception)
    ioexception.printStackTrace();
    //*************************SOTC***(client class)*********************
    import java.io.*;
    import java.net.Socket;
    import java.net.UnknownHostException;
    class SOTC implements Runnable
    private Socket socket;
    private ObjectOutputStream output;
    private ObjectInputStream input;
    public void start()
    try
    socket= new Socket("127.0.0.1",4444);
    input= new ObjectInputStream(socket.getInputStream());
    output= new ObjectOutputStream(socket.getOutputStream());
    catch(IOException e){e.printStackTrace();}
    Thread outputThread= new Thread(this);
    outputThread.start();
    public void run()
    try
    do
    Message m=new Message("sadfsa",0);
    output.writeObject(m);
    Respond fromServer=null;
    fromServer=(Respond)input.readObject();
    }while(true);
    catch(NullPointerException e){run();}
    catch(Exception e){e.printStackTrace();}
    public SOTC()
    start();
    public void sendMessage(Message re)
    try
    Message k=new Message("sdasd",0);
    output.writeObject(k);
    output.flush();
    catch(Exception ioexception)
    ioexception.printStackTrace();
    System.exit(-1);
    public static void main(String args[])
    SOTC sotclient = new SOTC();
    try
    System.out.println("client obje sonrasi main");
    Message re=new Message("client &#305;m ben mesaj bu da iste",0);
    sotclient.sendMessage(re);
    System.out.println ("client gonderdi mesaji");
    catch(Exception e) {e.printStackTrace();}

    ObjectStreams send a few bytes at construct time. The OutputStream writes a header and the InputStram reads them. The InputStream constrcutor will not return until oit reads that header. Your code is probably hanging in the InputStream constrcutor. (try and verify that by getting a thread dump)
    If that is your problem, tolution is easy, construct the OutputStreams first.

  • Problem with socket object writing

    hi,
    I made this little programm , with a class point , a server and a client.
    I try to send via the socket several point object.
    If send differents objects ( with several new point(... )) it works fine , but if i send the same object changing only the properties it doesn't work. Changing are not applicate.
    Here is the code.
    // POINT
    import java.io.Serializable;
    import java.awt.*;
    public class point implements Serializable{
        private int x_;
        private int y_;
        private Color c_;
        public point(int x, int y, Color c) {
           x_=x;
           y_=y;
           c_=c;
        public int get_x() { return x_ ; }
        public int get_y() { return y_ ; }
        public void set_x(int x) { x_=x ; }
        public void set_y(int y) { y_=y ; }
        public Color get_color() { return c_ ; }
    // SERVER
    import java.io.*;
    import java.net.*;
    public class s {
        public s()
            try
                ServerSocket server = new java.net.ServerSocket(80);
                java.net.Socket client  = server.accept();
                ObjectInputStream Istream_ = new ObjectInputStream(client.getInputStream());
                ObjectOutputStream Ostream_ = new ObjectOutputStream(client.getOutputStream());
                for(int i=0;i<4;i++)
                    point p_read = (point)Istream_.readObject();
                    System.out.print("x="+p_read.get_x());
                    System.out.println(" y="+p_read.get_y());
             catch (Exception exception) { exception.printStackTrace(); }
        public static void main(String args[])
         s s_ = new s();
    // CLIENT
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    public class c {
        public c()
            try
                ipJDialog ipjd = new ipJDialog();
                String ip = ipjd.getvalue();
                Socket socket  = new Socket(ip,80);
                System.out.println("connection avec serveur reussi");
                ObjectOutputStream Ostream_ = new ObjectOutputStream(socket.getOutputStream());
                ObjectInputStream Istream_ = new ObjectInputStream(socket.getInputStream());
                point p1 = new point(50,50, new Color(255,0,0));
                Ostream_.writeObject(p1);
                point p2 = new point(22,30, new Color(255,0,0));
                Ostream_.writeObject(p2);
                point p3 = new point(8,7, new Color(255,0,0));
                Ostream_.writeObject(p3);
                point p4 = new point(2,1, new Color(255,0,0));
                Ostream_.writeObject(p4);
             catch (Exception exception) {exception.printStackTrace();}
        public static void main(String args[])
         c c_ = new c();
    // DIALOG TO GET IP FROM INPUTBOX
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class ipJDialog extends JDialog implements ActionListener {
        private String ip_;
        private JTextArea jta_;
        private JTextField jtf_;
        private JButton jb1_;
        public ipJDialog()
            this.getContentPane().setLayout(null);
            this.setTitle("Entrez l'IP du serveur");
            this.setSize(220,100);
            this.setModal(true);
            ip_= "localhost";
            jta_ = new JTextArea("IP du serveur :");
            jta_.setBounds(10,5, 90,20);
            jta_.setOpaque(false);
            jta_.setEditable(false);
            getContentPane().add(jta_);
            jtf_ = new JTextField();
            jtf_.setBounds(110,5, 90,20);
            jtf_.requestFocus();
            getContentPane().add(jtf_);
            jb1_ = new JButton("OK");
            jb1_.setBounds(10,30, 90,30);
            jb1_.addActionListener(this);
            getContentPane().add(jb1_);
            this.setVisible(true);
        public String getvalue() { return ip_ ; }
        public void actionPerformed(ActionEvent evt)
            String ChoixOption = evt.getActionCommand();
         if(ChoixOption.equals("OK"))
                ip_=jtf_.getText();
                this.setVisible(false);
    if I replace in client :
             point p1 = new point(50,50, new Color(255,0,0));
                Ostream_.writeObject(p1);
                point p2 = new point(22,30, new Color(255,0,0));
                Ostream_.writeObject(p2);
                point p3 = new point(8,7, new Color(255,0,0));
                Ostream_.writeObject(p3);
                point p4 = new point(2,1, new Color(255,0,0));
                Ostream_.writeObject(p4);
    by :
             point p = new point(50,50, new Color(255,0,0));
                Ostream_.writeObject(p);
                p.set_x(20);
                p.set_x(22);
                Ostream_.writeObject(p);
                p.set_x(55);
                p.set_x(32);
                Ostream_.writeObject(p);
                p.set_x(14);
                p.set_x(88);
                Ostream_.writeObject(p);
    I doesn't work , i receive a point with 50,50 ( the first one ) four times ...If you can explain me me why and what can I do ...
    Thx.

    For ObjectOutputStream, multiple references to a single object are encoded using a reference sharing mechanism so that graphs of objects can be restored to the same shape as when the original was written. State of a object will be recorded so that the ObjectOutputStream doesn't writes the same object to the outputstream when the object was refered by multiple references. So, when you tried to write the same object agains into the ObjectOutputStream, the ObjectOutputStream doesn't write the object, but passed the as a reference to the outputstream... In this case, on the other side, the ObjectInputStream will receive this reference and it will return the reference of this object (which is previous created when this object was passed over on the 1st time). This caused the ObjectInputStream will return a "unchanged" object even your object have changed before you write it agains to the ObjectOutputStream.
    My explaination maybe not that good... hope you can understand... :)

  • Send mail with business object link

    Hi,
    can anyone please tell me, how can i send a mail with an business object as an attachement. when i clik on attachment, it should execute the method of business object which will display the document.
    it will be a great help,if any one can send the code.
    Thanks,
    naresh.

    Hi,
    You need classes CA_SAPUSER_BCS and CL_CAM_ADDRESS_BCS .
    CLASS ca_sapuser_bcs DEFINITION LOAD.
    CLASS cl_cam_address_bcs DEFINITION LOAD.
    You require the following local variables:
    DATA: send_request TYPE REF TO cl_bcs.
    DATA: document TYPE REF TO cl_document_bcs.
    DATA: sender TYPE REF TO cl_sapuser_bcs.
    DATA: recipient TYPE REF TO if_recipient_bcs.
    DATA: exception_info TYPE REF TO if_os_exception_info,
    bcs_exception type ref to cx_bcs.
    DATA: num_rows type i.
    DATA: textlength type SO_OBJ_LEN.
    First create a mail request:
    send_request = cl_bcs=>create_persistent( ).
    Create the mail sender:
    Get sender object
    sender = cl_sapuser_bcs=>create( sy-uname ).
    Add sender
    CALL METHOD send_request->set_sender
    EXPORTING i_sender = sender.
    You can define your mail address in this Web Application Server in the user maintenance.
    The mail can be sent to one or more addresses:
    Create recipient
    data: c_address TYPE ADR6-SMTP_ADDR.
    move mail_address to c_address.
    recipient = cl_cam_address_bcs=>create_internet_address(
    c_address ).
    Add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
    EXPORTING
    i_recipient = recipient
    i_express = ' '
    i_copy = ' '
    i_blind_copy = ' '.
    You receive the mail address as a string and you have to convert in into the required data type.
    The mail is sent to one address only without any additional attributes.
    You can now send the mail and write everything to the database.
    Send document
    CALL METHOD send_request->send( ).
    COMMIT WORK.
    You still have not taken any precautions against error situations.
    You can take care of this by embedding the following code in a TRY – CATCH block:
    try.
    ... Now the code comes after the creation of send_request up to the COMMIT WORK:
    catch cx_bcs into bcs_exception.
    if messages is not initial.
    messages->add_message( condition = 'mail'
    message =
    'Error occurred while sending the mail' )."#EC NOTEXT
    endif.
    exit
    endtry.
    Reward if it is helpful.
    Regards,
    Rajesh

  • Kindly send me some Objects with explanation If u have

    Hi all,
    I am Santosh .. I am new to this group .. I am in US with H1 .. I am looking for a job in SAP ABAP ..
    Kindly any one of you guys send me important interview tips and ansewrs as i am dam new to everything including the place...
    And one more thing please send me the Objects with explanation to explain in the interview..
    Kindly help me out yaar to get a job ... Plzzzzz
    Thanks  a lot
    Santosh

    Hi
    for some ABAP technical information check this out,
    http://help.sap.com/printdocu/core/Print46c/en/Data/htm/english.htm
    then  PDF files, AbapProgramimg,
    regards,

  • TS3276 I can't send messages with mail 6.0 of mountain lion, because I can't desactivate the option SSL (Secure sockets Layers); it is locked

    I can't send messages with mail 6.0 of mountain lion, because I can't desactivate the option SSL (Secure sockets Layers); it is locked

    Hi, i am having the same problem. this is what i have noticed.
    I have 2 x imac's and 2 x macbook air's
    i upgraded the 2 macbook air's and 1 of the imac's to Mountain Lion, all these have problems acessing sites that require you to login .
    the one remaining imac is still running lion and works perfect.
    i am using a dlink router with DD-WRT firmware, i tested teathering from my iphone and i can log into websites fine using the newly upgraded mac's.
    It's not a wireless issue as my imac is using an ethernet connection.
    is there a compatibility issue with some routers.

Maybe you are looking for