RE: Sending jpg bytes over a server

I had another topic but it has not been answered for a couple days so I guess I will clarify my problem more.
I'm sending my image over a server, Client->Server->Client.
My sending and receiving works but I get the image and it cannot be displayed.
Sending
try{
              FileInputStream fis = new FileInputStream("picture.jpg");
              byte[] buffer = new byte[fis.available()];
              fis.read(buffer);
              return buffer;
         }catch(Exception e){
              System.out.println("Loading Image error");
         }Receiving
         try{
              FileOutputStream fos = new FileOutputStream("received.jpg");
              fos.write(image);
              ImageIcon display = new ImageIcon("received.jpg");
              clientDisplayPicture=new JLabel(display);
         }catch(Exception h){
              System.out.println("Problem receiving");
         }Am I packaging it wrong? The received image is 0bytes. Thanks in advance!

Here you are ignoring the result of the read() method.Meaning?
Here you are not telling us how the incoming data got into 'image'.I put the bytes of the image into an object and passed it over the network.
    public void displayPicture(String from, byte[] image, boolean a, boolean b){
         try{
              FileOutputStream fos = new FileOutputStream("received.jpg");
              fos.write(image);
              fos.close();
         }catch(Exception h){
              System.out.println("Problem receiving");
    public byte[] getImage(){
         try{
              FileInputStream fis = new FileInputStream("picture.jpg");
              File f = new File("picture.jpg");
              int bsize = 1375;
              byte[] buffer = new byte[bsize];
              fis.read(buffer);
              fis.close();
              return buffer;
         }catch(Exception e){
              System.out.println("Loading Image error");
         return null;
    }EDIT: Thanks, got it working, the above worked. THANKS!
Edited by: Krytical on Aug 10, 2008 12:09 AM

Similar Messages

  • Send Bytes over TCP/IP

    {noformat}I am trying to send an array of bytes over tcp using OutputStream to a chat dispatch server, but few extra bytes are getting added at the begining and
    at the end of the original data I want to send.
    Why is this hapening and how do I overcome this?{noformat}

    ejp wrote:
    byte[] consisted of byte array converted from this hex dumpConverted how?
    If you use a String as a container for this binary data it will be corrupted.I declared the dump as a string like:
    "8A00000000000000000000000B000000476174656B6565706572320F0000004765744C6F67696E536572766572735C0000001800000052656469666620426F6C382E3020206275696C6420323735030000000A00000052424F4C2F312E322E351700000052424F4C2F312E322E352B485454505F434F4E4E4543540F00000052424F4C2F312E322E352B48545450"
    after this what should i do?
    what I am doing is
    1. extract two characters from the string at a time
    2. join them to make a string of two characters
    3. then treat that string as a hex value
    4. convert that hex value to its ascii-char equivalent( so i get an array of characters )
    5. convert the array of characters to array of bytes and send .
    I think that there is a better way to do this. Please suggest. So that no problem occurs.

  • How do u get the data from server? if server send by bytes?

    how do u get the data from server? if server send by bytes?
    i have tried using bufferedinputstream to get the data n getting the bytes but there is some data missing.i couldnt all data.so my image cant be display

    If you don't get helpful replies, I suggest you try to improve your question style a bit. There are many non native English speakers around here and the ability to phrase slick sentences varies. But for a start you could try to adhere to minimal English language standards like starting a sentence with an uppercase letter, and ending a sentence with a dot and a blank to separate it from the next sentence. Don't use ellipses (...) all over the place suggesting that the reader knows what you want to say. Rather please say it.
    Its is good style to only post the necessary code to understand the problem. However, the code you posted seems to be cut off too early to even get a grasp at what you are trying to achieve.
    Harald.
    BioMed Information Extraction: http://www.ebi.ac.uk/Rebholz-srv/whatizit

  • Sending byte array to server

    Does anyone know how to send a byte array to the server?

    What is contained in the byte array? Is it audio/video/image?
    If you can get a binary representation of it, you could probably
    convert it to Base64 and send it over as a string and reconvert to
    binary on the server.

  • How to send email to a SMTP server over a secure channel using STARTTLS setting of a send connector (Exchange and SMTP server are in the same domain)

    I’m trying to send email using exchange send connector STARTTLS setting to the SMTP server. I have read multiple documents on configuring TLS for send connector, but they talks about outbound connections to internet facing servers. My Exchange 2013 and SMTP
    server is in the same domain (let’s say A.com) and I’m creating dummy domains on my SMTP server (e.g.
    [email protected],
    [email protected] ) and their respective send connectors on the exchange server end. In the smart host section added the IP address of the SMTP server and in the scoping section added the SMTP domain address (e.g. dummy1.local ). In the FQDN field, added
    the FQDN of the exchange server 2013 which certificate is enabled with SMTP service.
    Could you tell me a step by step procedure, where I’m going wrong or any extra settings needs to added?
    Presently, it is giving me an error that 530 5.5.1 TLS encrypted connection is required.
    Note: I’ve created the Microsoft CA certificates for the SMTP and exchange servers and imported them in the personal certificate container. In which, the exchange certificate is created with FQDN name of the server and enabled for the SMTP service.
    I’m using OPENSSL certificate for making the SMTP server TLS enabled. (let me know, if I need to import the OPENSSL certificate anywhere on the exchange end)?
    Thanks!

    -IgnoreSTARTTLS is set to false on the send connector properties.
    I'm trying to established a HTTP over TLS connection. I'm not using mutual TLS between these two server.
    The send connector protocol logging is attached as below,
    2014-09-22T20:09:45.468Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,2,10.219.3.74:24939,10.219.3.73:25,<,220 SMTP.A.local Welcome (MTA version),
    2014-09-22T20:09:45.546Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,3,10.219.3.74:24939,10.219.3.73:25,>,EHLO Exchange.A.local,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,4,10.219.3.74:24939,10.219.3.73:25,<,250-SMTP.A.local Exchange.A.local OK,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,5,10.219.3.74:24939,10.219.3.73:25,<,250-SIZE,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,6,10.219.3.74:24939,10.219.3.73:25,<,250-8BITMIME,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,7,10.219.3.74:24939,10.219.3.73:25,<,250-BINARYMIME,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,8,10.219.3.74:24939,10.219.3.73:25,<,250-PIPELINING,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,9,10.219.3.74:24939,10.219.3.73:25,<,250-HELP,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,10,10.219.3.74:24939,10.219.3.73:25,<,250-DSN,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,11,10.219.3.74:24939,10.219.3.73:25,<,250-CHUNKING,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,12,10.219.3.74:24939,10.219.3.73:25,<,250-AUTH SCRAM-SHA-1 GSS-SPNEGO DIGEST-MD5 CRAM-MD5 NTLM,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,13,10.219.3.74:24939,10.219.3.73:25,<,250-AUTH=SCRAM-SHA-1 GSS-SPNEGO DIGEST-MD5 CRAM-MD5 NTLM,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,14,10.219.3.74:24939,10.219.3.73:25,<,250-STARTTLS,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,15,10.219.3.74:24939,10.219.3.73:25,<,250-DELIVERBY,
    2014-09-22T20:09:45.624Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,16,10.219.3.74:24939,10.219.3.73:25,<,250-MT-PRIORITY,
    2014-09-22T20:09:45.640Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,17,10.219.3.74:24939,10.219.3.73:25,<,250 ENHANCEDSTATUSCODES,
    2014-09-22T20:09:45.655Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,18,10.219.3.74:24939,10.219.3.73:25,>,STARTTLS,
    2014-09-22T20:09:45.671Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,19,10.219.3.74:24939,10.219.3.73:25,<,220 2.7.0 Ready to start TLS,
    2014-09-22T20:09:45.687Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,20,10.219.3.74:24939,10.219.3.73:25,*,,Sending certificate
    2014-09-22T20:09:45.687Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,21,10.219.3.74:24939,10.219.3.73:25,*,CN=Exchange.A.local,Certificate subject
    2014-09-22T20:09:45.687Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,22,10.219.3.74:24939,10.219.3.73:25,*,"CN=DC-CA, DC=A, DC=local",Certificate issuer name
    2014-09-22T20:09:45.687Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,23,10.219.3.74:24939,10.219.3.73:25,*,63E7E70100000000000B,Certificate serial number
    2014-09-22T20:09:45.687Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,24,10.219.3.74:24939,10.219.3.73:25,*,CAEB1200CDF49715E5F2E4B8315EFDDC01F8F945,Certificate thumbprint
    2014-09-22T20:09:45.780Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,25,10.219.3.74:24939,10.219.3.73:25,*,Exchange.A.local,Certificate alternate names
    2014-09-22T20:09:46.654Z,Exchange-SMTP send connector,08D1A4A14C7EDED5,26,10.219.3.74:24939,10.219.3.73:25,-,,Local
    2014-09-22T20:09:46.669Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,0,,10.219.3.73:25,*,,attempting to connect
    2014-09-22T20:09:46.685Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,1,10.219.3.74:24940,10.219.3.73:25,+,,
    2014-09-22T20:09:46.701Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,2,10.219.3.74:24940,10.219.3.73:25,<,220 SMTP.A.local Welcome (MTA version),
    2014-09-22T20:09:46.701Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,3,10.219.3.74:24940,10.219.3.73:25,>,EHLO Exchange.A.local,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,4,10.219.3.74:24940,10.219.3.73:25,<,250-SMTP.A.local Exchange.A.local OK,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,5,10.219.3.74:24940,10.219.3.73:25,<,250-SIZE,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,6,10.219.3.74:24940,10.219.3.73:25,<,250-8BITMIME,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,7,10.219.3.74:24940,10.219.3.73:25,<,250-BINARYMIME,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,8,10.219.3.74:24940,10.219.3.73:25,<,250-PIPELINING,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,9,10.219.3.74:24940,10.219.3.73:25,<,250-HELP,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,10,10.219.3.74:24940,10.219.3.73:25,<,250-DSN,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,11,10.219.3.74:24940,10.219.3.73:25,<,250-CHUNKING,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,12,10.219.3.74:24940,10.219.3.73:25,<,250-AUTH SCRAM-SHA-1 GSS-SPNEGO DIGEST-MD5 CRAM-MD5 NTLM,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,13,10.219.3.74:24940,10.219.3.73:25,<,250-AUTH=SCRAM-SHA-1 GSS-SPNEGO DIGEST-MD5 CRAM-MD5 NTLM,
    2014-09-22T20:09:46.716Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,14,10.219.3.74:24940,10.219.3.73:25,<,250-STARTTLS,
    2014-09-22T20:09:46.732Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,15,10.219.3.74:24940,10.219.3.73:25,<,250-DELIVERBY,
    2014-09-22T20:09:46.732Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,16,10.219.3.74:24940,10.219.3.73:25,<,250-MT-PRIORITY,
    2014-09-22T20:09:46.732Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,17,10.219.3.74:24940,10.219.3.73:25,<,250 ENHANCEDSTATUSCODES,
    2014-09-22T20:09:46.810Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,18,10.219.3.74:24940,10.219.3.73:25,*,,sending message with RecordId 52652004081667 and InternetMessageId <[email protected]>
    2014-09-22T20:09:46.810Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,19,10.219.3.74:24940,10.219.3.73:25,>,MAIL FROM:<> SIZE=7653 BODY=BINARYMIME,
    2014-09-22T20:09:46.810Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,20,10.219.3.74:24940,10.219.3.73:25,>,RCPT TO:<[email protected]>,
    2014-09-22T20:09:46.825Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,21,10.219.3.74:24940,10.219.3.73:25,<,530 5.5.1 A TLS-encrypted connection is required,
    2014-09-22T20:09:46.950Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,22,10.219.3.74:24940,10.219.3.73:25,<,503 5.5.1 unexpected RCPT command,
    2014-09-22T20:09:46.981Z,Exchange-SMTP send connector,08D1A4A14C7EDED6,23,10.219.3.74:24940,10.219.3.73:25,>,RSET,

  • Send BufferedOutputStream content over network in the order I choose

    Hi,
    The following method send a file over the network, it sends a couple of bytes arrays, including a file.
    I need to include the byte arrays and the file array in the same output buffer, and in my code i'm reading the File first to "outFileBuffer.write(buffer, 0, len);" to get the length, and then creating another buffer with the rest of the arrays.
    If there was a way to copy the from one buffer to another i had my problem fixed.
    public void sendOrder() {
            //Enviar encomenda (ver protocolo para identificar formatação dos pacotes)
            byte[] tipo = new byte[2];
            byte[] dataLength = new byte[4];
            byte[] fileNameLength = new byte[4];
            byte[] fileName;
            byte[] fileLength = new byte[4];
            byte[] file;
            String fxName;
            int fxNameLength;
            int len;
            int fxLength = 0;
            int length;
            int BUFFER_SIZE = 1024*50;  
            byte[] buffer = new byte[BUFFER_SIZE];
            fxName = "EO10001.DAD";
            fileName = fxName.getBytes();
            //Get and Send File Block
            try{
                //Get File Stream
                InputStream is = new FileInputStream("c:\\encomendas\\" + fxName);
                //Open Output Streams to send data to server
                OutputStream out = socket.getOutputStream();
                outBuffer = new BufferedOutputStream(out);
                while ((len = is.read(buffer)) > 0){
                    outFileBuffer.write(buffer, 0, len);
                    fxLength = fxLength + len;
                    System.out.println(fxLength);
                //initialize file byte array with file length size
                file = new byte[fxLength];
                //Wrap data into ByteBuffers
                ByteBuffer tipoBB = ByteBuffer.wrap(tipo);
                ByteBuffer dataLengthBB = ByteBuffer.wrap(dataLength);
                ByteBuffer fileNameLengthBB = ByteBuffer.wrap(fileNameLength);
                ByteBuffer fileNameBB = ByteBuffer.wrap(fileName);
                ByteBuffer fileLengthBB = ByteBuffer.wrap(fileLength);
                ByteBuffer fileBB = ByteBuffer.wrap(file);
                //Order data to least significant byte first
                tipoBB.order(ByteOrder.LITTLE_ENDIAN);
                dataLengthBB.order(ByteOrder.LITTLE_ENDIAN);
                fileNameLengthBB.order(ByteOrder.LITTLE_ENDIAN);
                fileLengthBB.order(ByteOrder.LITTLE_ENDIAN);
                //Fill the arrays with the data
                tipoBB.put((byte) 0,(byte) 4);
                fxNameLength=fxName.length();
                length = 32 + fxNameLength + 32 + fxLength;
                dataLengthBB.putInt(length);
                fileNameLengthBB.putInt(fxNameLength);
                fileNameBB.put(fileName);
                fileLengthBB.putInt(fxLength);
                //fileBB.putInt();
                //Write and flush the data to Stream
                incoming.append("\n\nSending file...");
                outBuffer.write(tipo);
                outBuffer.write(dataLength);
                outBuffer.write(fileNameLength);
                outBuffer.write(fileName);
                outBuffer.write(fileLength);
                outBuffer.flush();
                outBuffer.close();
                out.close();
                outFileBuffer.flush();
                debugData(tipo, dataLength, fileNameLength, fileName, fileLength, file); //append data to JTextArea for debugging purposes
            } catch (IOException ex){
                ex.printStackTrace();
    } // close methodThanks in advance for your help, I hope I was clear.
    Regards.

    darted wrote:
    That is not contrary to what I said - FIFO - first in First out.
    Yes, your buffer stream - (not TCP/IP packet (your stream will be broken up into many packets) by the way but still they are seeing it as two separate communications.
    So, timing will be an issue since you do not want them timing your communication out.
    You are sending known sizes on everything else, so create an out buffer of the inbuffer size plus known additional then send the two to the out stream. That will hopefully prompt them to look for complete data.
    Are you sure they are not timing out your communication?
    Edited by: darted on Dec 17, 2008 2:46 PMYou are right, it's FIFO, what i meant to say is that, the same order that i put things in the buffer is the same order that goes out to the stream, so it's the order i like it to be.
    What i realize from my testing is that whatever i put in the buffer before sending it, goes all in one packet (because is a small amount of data off course, but this will always be true), so i figure, if i can put the file in the same buffer I had my problem fixed, so sending two buffers (which is what i already was doing) is not, i think, the solution i want.
    They are not timing out my communication that i know, in the log file i can see that it receives my first packet, but it says the packet is incomplete (because the file should be part of this packet) :S
    Sure their's application should be able to get around this, but that's out of my control unfortunately.
    I'm still trying to put everything else in the same buffer before sending it.

  • Send wav files over a network

    Hi folks,
    I need to send sound files over a network. The files I'm wanting to send are wav files. I kinda have the mechanism that sends a file, but I am not sure how to convert wav files into something that I can easily send. Do I need to convert them into bytes, serialize them...etc I don't know.
    Can anyone please point me in the right direction? An example would be very much appreciated.
    Thank you,
    E

    hi
    this is very simple
    convert voice to bytearray
    just create one server socket and client socket then connect a sockets and transmit
    download sample from
    http://javasolution.blogspot.com/2007/04/voice-chat-using-java.html

  • How do I send an Image over a socket ?

    I'm trying to get the output from my webcam and send that data out to a socket. Now the output from the webcam is running I'm just not sure how to send it out over the socket.
    Server.java
    import java.io.*;
    import java.net.*;
    public class Server {
       public static void main(String args[]) {
         ServerSocket serverSocket = null;
         boolean listening = true;
         try {
         serverSocket = new ServerSocket(1354);
         System.out.println("Listening for Connections...");
         } catch (IOException drr) {
         System.out.println("Error Listening :" + drr);
         System.exit(-1);
         try {
         while(listening)
         new ServerThread(serverSocket.accept()).start();
         } catch (IOException er) {
         System.out.println("Error Creating connection:" + er);
         try {
           serverSocket.close();
         } catch (IOException err) {
         System.out.println("Error Closing:" + err);
    }When a connection is made it will start the webcam and send the image.
    ServerThread.java
    import java.net.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import javax.media.*;
    import javax.media.format.*;
    import javax.media.util.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import com.sun.image.codec.jpeg.*;
    public class ServerThread extends Thread {
        public static Player player = null;
        public CaptureDeviceInfo di = null;
        public MediaLocator ml = null;
        public JButton capture = null;
        public Buffer buf = null;
        public Image img = null;
        public VideoFormat vf = null;
        public BufferToImage btoi = null;
        public ImagePanel imgpanel = null;
        private Socket socket = null;
        Image blah;
        PrintWriter out = null;
        public ServerThread(Socket socket) {
         super("ServerThread");
         this.socket = socket;
        public void run() {
         try {
             out = new PrintWriter(socket.getOutputStream(), true);        
             imgpanel = new ImagePanel();
                 String str1 = "vfw:CompUSA PC Camera:0";
                 String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
                 di = CaptureDeviceManager.getDevice(str2);
             ml = new MediaLocator("vfw://0");
                try {
               player = Manager.createRealizedPlayer(ml);
                 } catch (Exception npe) {
               System.out.println("Player Exception:" + npe);
                player.start();
             Component comp;
             if ((comp = player.getVisualComponent()) != null) {
               // Grab a frame
               FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
               buf = fgc.grabFrame();
               btoi = new BufferToImage((VideoFormat) buf.getFormat());
               //Send the image over the socket
               out.println(btoi);
         } catch (IOException e) {
             System.out.println("It bombed:" + e);
        public static void playerclose() {
           player.close();
           player.deallocate();
      class ImagePanel extends Panel {
        public Image myimg = null;
        public ImagePanel() {
        public void setImage(Image img) {
          this.myimg = img;
          repaint();
        public void paint(Graphics g) {
          if (myimg != null) {
            g.drawImage(myimg, 0, 0, this);
      }The output I get from running the server is this:
    BufferedImage@c9131c: type = 1 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0 IntegerInterleavedRaster: width = 320 height = 240 #Bands = 3 xOff = 0 yOff = 0 dataOffset[0] 0
    Now how can I turn this into an image If this output is correct?

    HUH?
    I got the one to send the images over the network. I'm now trying to get the exact feed of the webcam and sending that over the network. This is alot more difficult to accomplish but I did see where I messed up my process of sending the images was just having to save the file then open it up put it in a byte array then send that over the network to the client. Once it was at the client i was able to re-construct it and throw it up in the frame. The only problem was lag. So this tells me it would be much more faster if instead of saving the file to send the client and having to reconstruct the image I should just send the webcam feed i used to make the image.
    eh, I guess I didn't need any help.
    Hey no offense or anything but you really have to learn how to spell better.

  • Sending a image over a network

    Hi all,
    Here is the problem. I want to send an Image from 1 computer to another computer over the internet using java... 1 computer is a server... that loads a image from harddisk or other resource (internet) and sends this to the other pc (client applet)
    How do I send and read it to create an image... ObjectStream is not an options because that does not support Image objects (or am I wrong here?)
    Please help
    Greetingz
    David

    Here is one way to to do it. Read the image file as a stream of bytes, send it to the client. On the client-side, create the image from the bytes received.
    Here is an example using RMI:
    Loading images ad bytes on the server side:
    public synchronized byte[] loadImageAsBytes(String filename)throws java.rmi.RemoteException {
          try {
            FileInputStream bis = new FileInputStream(filename);
            byte[] imageBuf = new byte[1024];
            ByteArrayOutputStream boutstream = new ByteArrayOutputStream();
            for(;;){
              int bytesread = bis.read(imageBuf);
              if (bytesread <0) {break;}
              boutstream.write(imageBuf,0,bytesread);
            byte[] pixmap =boutstream.toByteArray();
            return pixmap;
          } catch (Exception e) {return null;}
       }In this example, loadImageAsBytes() is a remote method.
    Here is how you can the image on the client side:
    byte[] buffer = loader.loadImageAsBytes(filename);
    Image img = Toolkit.getDefaultToolkit().createImage(buffer);The loader object was created using this statement:
    loader = (ImageLoader)Naming.lookup("SimpleImageServer");Note that ImageLoader is the interface that specifies the loadImageAsBytes() method.

  • Sending audio data over http problem

    Hi Guys,
    We are trying to create a little servlet in Tomcat, which is capable to send audio files over http to an embedded media player. The definition of the player looks like:
    <OBJECT ID="Mp" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" TYPE="application/x-oleobject" WIDTH="0" HEIGHT="0">
    <PARAM name="uiMode" value="none">
    <PARAM NAME="ShowControls" VALUE="0">
    <PARAM NAME="AutoStart" VALUE="1">
    <PARAM NAME="ShowPositionControls" VALUE="0">
    <PARAM NAME="ShowStatusBar" VALUE="0">
    <PARAM NAME="ShowDisplay" VALUE="0">
    </OBJECT>
    <script language="javascript">document.Mp.URL = "here comes the url of the servlet with item ID";</script>
    The servlet reads the audio file and writes its content to the response with the following http header settings:
    getResponse().setContentType("audio/x-wav");
    getResponse().setHeader("Content-Transfer-Encoding", "binary");
    getResponse().setHeader("Pragma", "Public");
    getResponse().setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    getResponse().setHeader("Content-Disposition", "inline; filename=Media.wav");
    getResponse().setHeader("Content-Length", new Integer(MediaBytes.length).toString());
    getResponse().setHeader("Accept-Ranges", "bytes");
    So, everything works fine for wav files in Internet Explorer, but we are facing problems with Firefox, where it does not work. The embedded Media Player says that "Windows Media Player cannot play the file. One or more codecs required to play the file could not be found."
    But if we set the url to directly to the file on the server, everything works fine.
    We have analyzed the HTTP traffic in both situation, but we cannot understand how Internet Explorer/Firefox and Media Player works together:
    - how does Media Player know that the audio file is playable?
    - if the url points directly to the file, the HTTP headers does not contain any kind of information about the file type, only the extension is available; Media Player checks the file extenion in the url?
    - if the url points to the servlet, why Media Player in Firefox cannot determine the file type and throws error?
    Any help is greately appreciated!
    Thanks!
    Gabor

    If you haven't already, I would try breaking down the problem. First confirm you're getting serial data then confirm that netcat can send some data. Like this:
    xxd < /dev/tty.usbmodemfa121 | less
    nc -u 10.0.1.3 7000 <<< 'hello over there'

  • PI 7.1 using FTPS as File Sender Adapter: Problem connecting to Server!

    Hi
    We are using SAP PI 7.1 and I am trying to connect to an FTPS Server, but always get the following Error in the log: "Channel FileReceiver: Error connecting to ftp server 'hostname': com.sap.aii.adapter.file.ftp.FTPEx: The control connection to the FTP server hostname timed out while reading the server reply."
    I checked all the parameters and they seem to be ok! When I am using the same parameters with a WS_FTP Client Tool on the same server, I can establish the connection! Hostname, Port, User, Pass, etc must be ok ... I also imported the CA Certificate into the "TrustedCAs" KeyStore ...
    We also checked if on FTPS Server side we can see anything in the logfiles, but it seems that PI (Fiel Adapter) does not send anything to the FTPS Server. On OS Level we see that a TCP Connection is established tho the Server on the correct Port and we also used a tool to analize if data is sent over the established connection, but there was no data :-o
    Can anybody help me?
    Thanks
    Christoph

    Hi Pavan
    Access rights are ok ... how do I check if my PI Sysem supports FTPS? We have installed the crypto extensions and I also can select the FTPS Option on the file adapter. Is there anything else that must be enabled or configured?
    Regards
    Christoph

  • What classes should I use to send/receive bytes inmediately?

    What classes should I use to send/receive bytes inmediately? I mean, without using any buffers or whatever (I will implement this on my app), just the faster method.
    Is InputStream/OutputStream the lowest level choice?
    Thanks!

    Hi!
    Thank you very much for your help, I appreciate it a lot.
    While I test my server, I execute ping www.myclienthost.com -t (my client games are in other office, in the same building, but different ISP) and I don't see anything strange, so I guess network is working perfectly. However, if I use wireshark (sniffer) and I see that my system fails (server does not send acks so client disconnects) is because my acks messages are not sended for 6 o 7 seconds (it should send them every 2 or 3). It seems thread is blocked. and after 6 or 7 seconds one message with 2 or 3 acks together is sent. So, I see that the thread handler blocked for a few seconds and this is doing my server is failing. Why client handler thread on my server is blocked? One question: every 2 or 3 seconds I have a thread that uses sleep that iterates thru client handlers and takes OutputStream and send one ack message for every client handler. My question is, in client handler class I have a method called SendInfo(String whatever) which encrypts and sends through OutputStream, should I protectd this method from accesing from two threads??? as acks thread and client thread can access at the same time. Could this be the problem??
    EDIT: In my previous post I forgot to say what I found out with wireshark. Here I explain it. Sorry.
    By the way, how can I debug threads?? I would like to know if my client thread is blocked in that critical moment.
    Thanks a lot for your ideas and sorry for my English.
    Edited by: Ricardo_Ruiz_Lopez on Jan 22, 2009 7:38 AM

  • Using NLB over Application Server in SharePoint 2010?

    I have two application server that I need to load balance using Microsoft NLB.
    My queries:
    1) Just load balancing the Application Server will load balance the SharePoint service as well?  
    2) How would service application on application server would response to the request that is coming via VIP,  what I want ask is where in IIS the physical ips be configured?
    3) Once I configure the NLB and have VIP pointing to two physical IPs, how would the Web Server knows that he has to send the request over the VIP(virtual ip) . Where is this configuration done?

    In the SharePoint world an 'application server' is a server that does not handle user traffic directly. It doesn't host the websites that users access but instead handles the behind the scenes processing such as searches, PowerPivot etc.
    For those servers you do not need to use load balancing, SharePoint handles load balancing internally for those services.
    If you want to load balance the web front ends (WFEs) which serve websites to users then this blog covers it quite comprehensively:
    http://blogs.technet.com/b/praveenh/archive/2010/12/17/setting-up-load-balancing-on-a-sharepoint-farm-running-on-windows-server-2008.aspx

  • How to send data back to the server

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

    i create a program to send data back to ther server using j2me.
    its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
    try {
    getGrade(url);
    } catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);
    }>

  • Send Data back to the Server

    Hi.
    how to send data back to the server using J2ME or how to communicate with server using J2ME

    i am using http its work well on emulator but when i install the application on sony ericsssin p910i or k700i or nokia 7710 then its not working and simply hang.
    here is sample code which is run well on emulator but not on mobile.
    what is the problem in that or how can this code run in mobile is there any mobile specific setting or internet setting.
    Pls reply asap.
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * An example MIDlet to invoke a CGI script.
    public class ThirdExample extends MIDlet {
    private Display display;
    // String url = "http://www.javacourses.com/cgi-bin/getgrade.cgi?idnum=182016";
    String url = "http://sampler.infopro.stpn.soft.net/midletdata.asp?name=name";
    public ThirdExample() {
    display = Display.getDisplay(this);
    * Initialization. Invoked when we activate the MIDlet.
    public void startApp() {
         try {
    getGrade(url);
         } catch (IOException e) {
         System.out.println("IOException " + e);
         e.printStackTrace();
    * Pause, discontinue ....
    public void pauseApp() {
    * Destroy must cleanup everything.
    public void destroyApp(boolean unconditional) {
    * Retrieve a grade....
    void getGrade(String url) throws IOException {
    HttpConnection c = null;
    InputStream is = null;
    OutputStream os = null;
    StringBuffer b = new StringBuffer();
    TextBox t = null;
    int x = 5, y =7;
    try {
    c = (HttpConnection)Connector.open(url);
    c.setRequestMethod(HttpConnection.GET);
    c.setRequestProperty("IF-Modified-Since", "10 Nov 2000 17:29:12 GMT");
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
    c.setRequestProperty("Content-Language", "en-CA");
    os = c.openOutputStream();
    String str = "?idnum=182016";
    byte postmsg[] = str.getBytes();
    for(int i=0;i<postmsg.length;i++) {
    os.writeByte(postmsg);
    os.flush();
    is = c.openDataInputStream();
    int ch;
    while ((ch = is.read()) != -1) {
    b.append((char) ch);
    System.out.println((char)ch);
    t = new TextBox("Final Grades", b.toString(), 1024, 0);
    } finally {
    if(is!= null) {
    is.close();
    if(os != null) {
    os.close();
    if(c != null) {
    c.close();
    display.setCurrent(t);

Maybe you are looking for