Tansfer files through socket

Hi all
Can anyone tell me that how can i send files from server to the client through socket programming.
if u recommend to send file using
int read(byte[] b, int offset, int blength)
void write( byte[] b, int offset, int blength) then how plz tell me how can use these methods to send a receive files??? if u give a small example code then i will very greatful to u.
Usman

Thanks for ur help.
but i have got it. i have designed a client and server. Client requests the server to send a specif file (Client takes the path of file from user). And server sends the file to the client.
I have checked this program on many files. like *.exe, *.txt, *.dat, *.zip, *.mp3, *.jpg.
it worked smoothly. I have test to trasfer a file of 700MB and it worked correctly.
Ooops! i did not check it on Network. i run these program on my own computer. both client and server were running on same computer.
but i am facing a little problem. that is: the speed of trasfering the files is very slow.
any1 know how to increase the speed of data transfer over the sockets ???
And plz tell me how can i trasfer a complete directory just as i trasfered file over the sockets. (Remember: a dircetory may or may not contains may other files and also other directories
thanks in advance...!!!
here is the code:
*          CLIENT            *
import java.net.*;
import java.io.*;
public class TransferClient
    public static void main(String[] args)
        try
             int fileSize = 0;
             int readBytes = 0;     
             final int BUFFER_SIZE = 512;
             byte[] buffer = new byte[BUFFER_SIZE];       
               Socket sockClient = new Socket(InetAddress.getLocalHost(),2000);     
               DataInputStream dataInputStream = new DataInputStream(sockClient.getInputStream());
               BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("filename.ext"));
               BufferedReader inputUser   = new BufferedReader(new InputStreamReader(System.in)); //For User input
               PrintWriter output = new PrintWriter (sockClient.getOutputStream(), true);     //To send the user input to the server
               //get path from user
               System.out.print("Enter the complete path of file: ");
               String path = inputUser.readLine();
               //send path to server
               output.println(path);
               readBytes = dataInputStream.readInt();
               while(readBytes > 0)
                    readBytes = dataInputStream.read(buffer, 0, readBytes);
                    fileSize = fileSize + readBytes;
                    bufferedOutputStream.write(buffer, 0, readBytes);
                    readBytes = dataInputStream.readInt();
               }//end while
               bufferedOutputStream.flush();
               System.out.println("Received Bytes:  " + fileSize);
               dataInputStream.close();
               bufferedOutputStream.close();                              
               inputUser.close();
               output.close();
               sockClient.close();
        }//end try
        catch(IOException ioException)
             ioException.printStackTrace();
        }//end catch
    }//end main()
}//end class TransferClient
*          SERVER            *
import java.io.*;
import java.net.*;
public class TransferServer
    public static void main(String[] args)
         int fileSize = 0;         
         int readBytes = 0;
         final int BUFFER_SIZE = 512;
         byte[] buffer = new byte[BUFFER_SIZE];
         try
              ServerSocket ss = new ServerSocket(2000);
              System.out.println("Server Strarts...");
              Socket sock = ss.accept();
              BufferedReader clientInput = new BufferedReader(new InputStreamReader (sock.getInputStream()));
               DataOutputStream dataOutputStream = new DataOutputStream(sock.getOutputStream());
               PrintWriter output = new PrintWriter(sock.getOutputStream(), true);
               System.out.println ("Connection Received");          
               String path = clientInput.readLine();               
               File f = new File(path);                    
               if( f.exists() )
                    BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(path));               
                    while((readBytes = bufferedInputStream.read(buffer))!= -1)
                         fileSize = fileSize + readBytes;
                         dataOutputStream.writeInt(readBytes);
                         dataOutputStream.write(buffer, 0, readBytes); 
                    }//end while
                    dataOutputStream.writeInt(0);          
                    System.out.println("Sent Bytes:  " + fileSize);
                    bufferedInputStream.close();
               }//end if
               clientInput.close();
               dataOutputStream.close();
         }//end try
         //catch(FileNotFoundException fileNotFoundException)
         //     output.println("Sorry! file does not exist.");
         catch(IOException ioException)
              ioException.printStackTrace();
         }//end catch       
    }//end main()
}//end class TransferServer

Similar Messages

  • Transfering a file through Socket programming

    Hi all,
    I want to return a file from server to client through a socket. I tried using ObjectOutput Stream where in I returned a java.io.File from server. But at client side when I say file.getLeangth() it comes as 0 and if I try to assign FileInputStream on the object it throws an exception as the file not found as the path associated with the file will be of Server.
    So can anyone help as to how to transfer a file through socket programming???
    thx in advance
    MK

    java.io.File is NOT the contents of the file. It really just represents the path.
    If you want to transfer the file's contents, you'll have to use a FileInputStream or FileReader, read from it, and then write the bytes or chars on the wire.

  • Send files through Sockets

    how do i send an entire file through a socket...?
    thank you....

    [http://forums.sun.com/thread.jspa?forumID=11&threadID=390636] this may help you

  • Transfering files through sockets

    Hi
    I am still having difficulties making this work.
    I want to transfer a file (.exe, .zip) etc through a socket.
    I have created a fileinputstream to the file, and read in all its bytes.
    I then create an outputstream with the sockets output stream(socket is called incomming):
    FileInputStream fin = new FileInputStream("D:\\steve.txt");
    int size = fin.available();//for they byte array!
    System.out.println("Number of bytes in this file is " + size);
    byte b[] = new byte[size];//byte buffer holds the exact number of bytes the file contains!
    fin.read(b);
    OutputStream fileSender = incomming.getOutputStream();
                   fileSender.write(b, 0, size);
                   fileSender.close();
    I am positive the byte array holds all the bytes in the file as i have tested that.
    The problem is i dont seem to get anything out the client end. I pass along the file size and construct a byte array to hold it this is the client code:
    InputStream inFile = soc.getInputStream();
    populateTextArea("reading bytes!");
    byte b[] = new byte[inLineNum]; //inLIneNum is the correct size for sure
    inFile.read(b,0, inLineNum);
    FileOutputStream foutnew = new FileOutputStream("C:\\TEMP01\\STevenTESTtest.txt");
    foutnew.write(b);
    The resulting file contains nothing, all it contains is a load of ascii code (00).
    Any suggestions please, I'm probably missing something really dumb but I've spent about 5 hours and am totally fed up with it.
    Steve

    hehe it was working all the time, its just that my test files are large (typically over 5 meg) so its taking ages to transfer....So, does anyone know how to speed up a socket connection (if its even possible).
    Cheers
    Steve

  • File thansfer through socket problem

    i am writing server /client program, where the server wait for client request to send or receive file through socket.
    can i use 1 socket to handle the request (client want to send or download file) and file data transfer?
    if yes, how to handle the beginging of file transfer after receive a request?
    and how can server know when the file transfer is completed?

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

  • Read contents of file into outputstream and send through socket

    I have a file. Instead of transferring the whole file through socket to the destination, I will read the contents from the file (big or small file size) into outputstream and send them to the destination where the client will receive the data and directly display it....
    Can you suggest any efficient way/methods to achieve that?
    Thanks.

    I don' t understand what you think the difference is between those two techniques, but:
    int count;
    byte[] buffer = new byte[16384];
    while ((count = in.read(buffer)) > 0)
      out.write(buffer, 0, count);
    out.close();
    in.close();

  • Sockets: can only send once file through

    Hi,
    I am using sockets to send text and files to a client on a Clio. I want to send multiple files through. However, only the first file goes through. The rest are never received (although they are uploaded). My question is:
    Why can not send anything through the socket (text or files) after the first file is sent?
    The fileSend() is on the server side, fileReceive is on the client side.
    public static void fileSend (Socket uploadSocket, String source) {
         try {
             InputStream inFile = new FileInputStream(source);
             InputStream in = new BufferedInputStream(inFile);
             OutputStream out = new BufferedOutputStream(uploadSocket.getOutputStream());
             System.out.println("Sending " + source + ".");
             int data;
             int bytes = 0;
             while ((data = in.read()) != -1) {
              bytes++;
              out.write(data);
             bytes++;
             out.write(data);
             if (in != null) in.close();
             if (out != null) out.flush();
             System.out.println("Upload complete: " + bytes + " Bytes!");
         catch (Exception e) {
             System.err.println("Couldn't upload " + source + ": " + e.getMessage());
       public static void fileReceive (Socket downloadSocket, String destination) {
         try {
             InputStream in = new BufferedInputStream(downloadSocket.getInputStream());
             OutputStream outFile = new FileOutputStream(destination);
             OutputStream out = new BufferedOutputStream(outFile);
             System.out.println("Downloading data to " + destination + ".");
             int data = in.read();
             int bytes = 0;
             while (data != -1) {
              bytes++;
              out.write(data);
              data = in.read();
             bytes++;
             if (out != null) {
              out.flush();
              out.close();
             outFile.close();
             System.out.println("Download complete: " + bytes + " Bytes!");
             in.skip(in.available());
         catch (Exception e) {
             System.err.println("Couldn't download " + destination + ": " + e.getMessage());
        }Thanks,
    Neetin

    I think its better to pass the outputstream to the filesend() method and inputstream to fileReceive() method
    something like this:
    OutputStream out = new BufferedOutputStream(uploadSocket.getOutputStream());
    public static void fileSend (OutputStream os, String source) {
      //write your file onto the output stream
    InputStream in = new BufferedInputStream(downloadSocket.getInputStream());
    public static void fileReceive (InputStream is) {
      //Read from the input stream
    }This should work.. Good luck

  • File reading through Sockets???

    Hello,
    My application has a server and it has to read a file that is sent by the client.. how can the server read a file sent by the client through sockets?????
    Edited by: s_coder on Feb 19, 2009 11:20 PM

    s_coder wrote:
    Yes i read it but there input is given from the client to the server through the standard input stream.... how can i transfer a file thru the standard input stream? and the accept it at the server side???Come on mate. You need to be able to add two and two on your own.
    WTF is a "standard input stream"? And why if you followed the tutorial can you not figure out how to send the data of a file through a socket?
    Either you didn't really read the tutorial or you're pretty darn hopeless. Why don't you try and really follow the tutorial, not just glance at each page but understand what it is saying. Then make an attempt to write your program and if you get stuck come back with your code. Be sure to use the code formatting tags when you show us your code.

  • Send many files through a socket without closing Buffered Streams?

    Hi,
    I have an application that sends/receives files through a socket. To do this, on the receiver side I have a BufferedInputStream from the socket, and a BufferedOutputStream to the file on disk.
    On the sender side I have the same thing in reverse.
    As you know I can't close any stream, ever.. because that closes the underlying socket (this seems stupid..?)
    therefore, how can I tell the receiver that it has reached the end of a file?
    Can you show me any examples that send/receive more than one file without closing any streams/sockets?

    Hi,
    As you know I can't close any stream, ever.. because that closes the underlying socket (this seems stupid..?)Its not if you want to continuosly listen to the particular port.. like those of server, you need to use ServerSocket.
    for sending multiple files the sender(Socket) can request the file to server (ServerSocket). read the contents(file name) and then return the file over same connection, then close the connection.
    For next file you need to request again, put it in loop that will be better.
    A quick Google gives me this.
    Regards,
    Santosh.

  • How to transfer a binary file through the socket?

    hi,
    i have a problem when I want to transfer a binary file through the socket. On the server side we write a program with C. On the client side with use java. The socket worked fine when we transfer some asci files. But failed when transfer the binary file. How to solve the problem? Can someone give me some advice? Thanks a lot.
    sincerely,
    zheng chuanbo

    i use streams to read the binary file. The problem is I don't know when the transfered stream finished. With text file I can recognize the end of the transfer by a special string, but how to deal with the end of a stream? should the server send an "EOF" or something else to the client to notify the end?

  • File transfer, read write through sockets in client server programming java

    Hello All, need help again.
    I am trying to create a Client server program, where, the Client first sends a file to Server, on accepting the file, the server generates another file(probably xml), send it to the client as a response, the client read the response xml, parse it and display some data. now I am successful sending the file to the server, but could not figure out how the server can create and send a xml file and send it to the client as response, please help. below are my codes for client and server
    Client side
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.InetAddress;
    import java.net.Socket;
    import java.net.UnknownHostException;
    public class XMLSocketC
         public static void main(String[] args) throws IOException
              //Establish a connection to socket
              Socket toServer = null;
              String host = "127.0.0.1";     
              int port = 4444;
              try
                   toServer = new Socket(host, port);
                   } catch (UnknownHostException e) {
                System.err.println("Don't know about host: localhost.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to host.");
                System.exit(1);
              //Send file over Socket
            //===========================================================
            BufferedInputStream fileIn = null;
              BufferedOutputStream out = null;
              // File to be send over the socket.
              File file = new File("c:/xampp/htdocs/thesis/sensorList.php");
              // Checking for the file to be sent.
              if (!file.exists())
                   System.out.println("File doesn't exist");
                   System.exit(0);
              try
                   // InputStream to read the file
                   fileIn = new BufferedInputStream(new FileInputStream(file));
              }catch(IOException eee)
                   System.out.println("Problem, kunne ikke lage fil");
              try
                   InetAddress adressen = InetAddress.getByName(host);
                   try
                        System.out.println("Establishing Socket Connection");
                        // Opening Socket
                        Socket s = new Socket(adressen, port);
                        System.out.println("Socket is clear and available.....");
                        // OutputStream to socket
                        out = new BufferedOutputStream(s.getOutputStream());
                        byte[] buffer = new byte[1024];
                        int numRead;
                        //Checking if bytes available to read to the buffer.
                        while( (numRead = fileIn.read(buffer)) >= 0)
                             // Writes bytes to Output Stream from 0 to total number of bytes
                             out.write(buffer, 0, numRead);
                        // Flush - send file
                        out.flush();
                        // close OutputStream
                        out.close();
                        // close InputStrean
                        fileIn.close();
                   }catch (IOException e)
              }catch(UnknownHostException e)
                   System.err.println(e);
            //===========================================================
            //Retrieve data from Socket.
              //BufferedReader in = new BufferedReader(new InputStreamReader(toServer.getInputStream()));
              DataInputStream in = new DataInputStream(new BufferedInputStream(toServer.getInputStream()));
              //String fromServer;
            //Read from the server and prints.
              //Receive text from server
              FileWriter fr = null;
              String frn = "xxx_response.xml";
              try {
                   fr = new FileWriter(frn);
              } catch (IOException e1) {
                   // TODO Auto-generated catch block
                   e1.printStackTrace();
              try{
                   String line = in.readUTF();                    //.readLine();
                   System.out.println("Text received :" + line);
                   fr.write(line);
              } catch (IOException e){
                   System.out.println("Read failed");
                   System.exit(1);
            in.close();
            toServer.close();
    public class XMLSocketS
          public static void main(String[] args) throws IOException
              //Establish a connection to socket
               ServerSocket serverSocket = null;
                 try {
                     serverSocket = new ServerSocket(4444);
                 } catch (IOException e) {
                     System.err.println("Could not listen on port: 4444.");
                     System.exit(1);
              Socket clientLink = null;
              while (true)
                        try
                             clientLink = serverSocket.accept();
                           System.out.println("Server accepts");
                             BufferedInputStream inn = new BufferedInputStream(clientLink.getInputStream());
                             BufferedOutputStream ut = new BufferedOutputStream(new FileOutputStream(new File("c:/xampp/htdocs/received_from_client.txt")));
                             byte[] buff = new byte[1024];
                             int readMe;
                             while( (readMe = inn.read(buff)) >= 0)
                             {     //reads from input stream, writes the file to disk
                                  ut.write(buff, 0, readMe);
                             // close the link to client
                             clientLink.close();                         
                             // close InputStream
                             inn.close();                         
                             // flush
                             ut.flush();                         
                             // close OutputStream
                             ut.close();     
                             //Sending response to client     
                             //============================================================
                             //============================================================
                             System.out.println("File received");
              }catch(IOException ex)
              {System.out.println("Exception.");}
                        finally
                             try
                                  if (clientLink != null) clientLink.close();
                             }catch(IOException e) {}
                 clientLink.close();
                 //serverSocket.close();
    }

    SERVER
    import java.net.*;
    import java.io.*;
    public class XMLSocketS
          public static void main(String[] args) throws IOException
                   //Establish a connection to socket
               ServerSocket serverSocket = null;
                 try {
                     serverSocket = new ServerSocket(4545);
                 } catch (IOException e) {
                     System.err.println("Could not listen on port: 4444.");
                     System.exit(1);
              Socket clientLink = null;
                  try
                             clientLink = serverSocket.accept();
                         System.out.println("Server accepts the client request.....");
                         BufferedInputStream inn = new BufferedInputStream(clientLink.getInputStream());
                             BufferedOutputStream ut = new BufferedOutputStream(new FileOutputStream(new File("c:/xampp/htdocs/received_from_client.txt")));
                             byte[] buff = new byte[1024];
                             int readMe;
                             while( (readMe = inn.read(buff)) >= 0)
                             {     //reads from input stream, writes the file to disk
                                  ut.write(buff, 0, readMe);
                             ut.flush();                         
                             //Sending response to client     
                             //============================================================
                             BufferedInputStream ftoC = null;
                             BufferedOutputStream outtoC = null;
                             // File to be send over the socket.
                             File file = new File("c:/xampp/htdocs/thesis/user_registration_response.xml");
                             try
                                  // InputStream to read the file
                                   ftoC = new BufferedInputStream(new FileInputStream(file));
                             }catch(IOException eee)
                             {System.out.println("Problem reading file");}
                             // OutputStream to socket
                             outtoC = new BufferedOutputStream(clientLink.getOutputStream());
                             byte[] buffer = new byte[1024];
                             int noRead;
                             //Checking if bytes available to read to the buffer.
                             while( (noRead = ftoC.read(buffer)) >= 0)
                                  // Writes bytes to Output Stream from 0 to total number of bytes
                                  outtoC.write(buffer, 0, noRead);
                             outtoC.flush();
                             //============================================================
                             System.out.println("File received");
              }catch(IOException ex)
              {System.out.println("Exception.");}
                        finally
                             try
                                  if (clientLink != null) clientLink.close();
                             }catch(IOException e) {}
                 clientLink.close();
                 //serverSocket.close();
          }CLIENT SIDE
    import java.io.*;
    import java.net.*;
    public class XMLSocketC
              @SuppressWarnings("deprecation")
              public static void main(String[] args)
                   // Server: "localhost" here. And port to connect is 4545.
                   String host = "127.0.0.1";          
                   int port = 4545;
                   BufferedInputStream fileIn = null;
                   BufferedOutputStream out = null;
                   // File to be send over the socket.
                   File file = new File("c:/xampp/htdocs/thesis/sensorList.xml");
                   try
                        // InputStream to read the file
                        fileIn = new BufferedInputStream(new FileInputStream(file));
                   }catch(IOException eee)
                   {System.out.println("Problem");}
                   try
                             System.out.println("Establishing Socket Connection");
                             // Opening Socket
                             Socket clientSocket = new Socket(host, port);
                             System.out.println("Socket is clear and available.....");
                             // OutputStream to socket
                             out = new BufferedOutputStream(clientSocket.getOutputStream());
                             byte[] buffer = new byte[1024];
                             int numRead;
                             //Checking if bytes available to read to the buffer.
                             while( (numRead = fileIn.read(buffer)) >= 0)
                                  // Writes bytes to Output Stream from 0 to total number of bytes
                                  out.write(buffer, 0, numRead);
                             // Flush - send file
                             out.flush();
                             //=======================================
                             DataInputStream in = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream()));
                             BufferedWriter outf = new BufferedWriter(new FileWriter("c:/xampp/htdocs/received_from_server.txt",true));
                             String str;
                             while(!(str = in.readLine()).equals("EOF")) {     
                                  System.out.println("client : Read line -> <" + str + ">");
                                  outf.write(str);//Write out a string to the file
                                  outf.newLine();//write a new line to the file (for better format)
                                  outf.flush();
                             //=======================================
                             // close OutputStream
                             out.close();
                             // close InputStrean
                             fileIn.close();
                             // close Socket
                             clientSocket.close();
                        }catch (IOException e)
                        {System.out.println("Exception.");}
         Could you please point where am I doing the stupid mistake, client to server is working properly, but the opposite direction is not.
    Thanks

  • Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'

    I'm using the pre-installed versions of php and mysql under Mac OS X Server 10.4.4 running on a G4 and am unable to get anything involving mysql to work.
    I ssh to the server and enter various commands in Terminal:
    on typing "mysql" I get
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)
    and on typing "mysqladmin version" I get
    mysqladmin: connect to server at 'localhost' failed
    error: 'Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)'
    Check that mysqld is running and that the socket: '/var/mysql/mysql.sock' exists!
    On typing "sudo mysqld_safe" I get
    Starting mysqld daemon with databases from /var/mysql
    STOPPING server from pid file /var/mysql/MyServer.local.pid
    070722 16:06:05 mysqld ended
    /var/mysql/MyServer.local.err contains
    070722 16:06:04 mysqld started
    070722 16:06:04 [Warning] Setting lowercase_tablenames=2 because file system for /var/mysql/ is case insensitive
    070722 16:06:04 InnoDB: Database was not shut down normally!
    InnoDB: Starting crash recovery.
    InnoDB: Reading tablespace information from the .ibd files...
    InnoDB: Restoring possible half-written data pages from the doublewrite
    InnoDB: buffer...
    070722 16:06:05 InnoDB: Starting log scan based on checkpoint at
    InnoDB: log sequence number 0 43634.
    /var/mysql has permissions 775.
    The line
    mysql.default_socket = /var/mysql/mysql.sock
    is in /etc/php.ini
    whereis mysqladmin ->
    /usr/bin/mysqladmin
    whereis mysql ->
    /usr/bin/mysql
    ls /var/mysql ->
    MyServer.local.err
    ib_logfile1
    mysql
    ib_logfile0
    ibdata1
    test
    Can't find my.cnf or my.ini anywhere
    Can't find mysql.sock anywhere
    I'm trying to get a bug database running (mantis) under Mac OS X Server 10.4.4 that I can access from local clients.
    I'm trying to follow directions at http://www.mantisbugtracker.com/manual/manual.installation.php
    without knowing anything about mysql or php and I'm stuck on step 3:
    "Next we will create the necessary database tables and a basic configuration
    file."
    I get a message saying
    "Does administrative user have access to the database? ( Lost connection to MySQL server during query )"
    I don't even know if following the mantis directions has resulted in the creation of a database or not. Where would it be?
    Thanks for any help.
    Intel iMac   Mac OS X (10.4.10)  

    I've just done a clean install of OSX Server and added the latest MYSQL packaged installer. Afterwards I found the lock file in /private/tmp/mysql.lock
    The easiest way to solve this problem is to create a symbolic link so that the lock file appears to be in right place.
    e.g.
    cd /var
    sudo mkdir mysql <== this assumes the directory is missing
    cd mysql
    sudo ln -s /private/tmp/mysql.sock mysql.sock
    After this msql commands should work fine, and you've not fiddled with the security settings on users/groups.
    HTH
    Christian

  • Logging through sockets

    Hi
    I'm trying to send logging information through sockets using log4j.
    My configuration file is :
    log4j.rootLogger=Debug, Socket
    log4j.appender.Socket=org.apache.log4j.net.SocketAppender
    log4j.appender.Socket.Port=12345
    log4j.appender.Socket.RemoteHost=localhost
    log4j.appender.Socket.LocationInfo=true
    the server only reads the input string that the logger sends.
    I'm getting this exception on the client side:
    log4j:WARN Detected problem with connection: java.net.SocketException: Software caused connection abort: socket write error
    and this message on the server:
    Server started...
    Client accepted
    ������������org.apache.log4j.spi.LoggingEven�������������

    Ryan,
    I think if I could log to something common like Microsoft Access it would be a help to me in managing database backups and other things, as Citadel is somewhat unique in its format and methods using the Measurement and Automation Explorer. Maybe I could retrieve data from a 3rd party database back into Citadel if Citadel DB becomes corrupted or lost.
    I don't use ODBC logging now, so please excuse me if I come across as lacking in understanding your request. Could the hypertrend or other objects be programmed to log and/or retrieve data to and/or from the 3rd party ODBC database as well?
    Terry Parks, Engineering Analyst
    Terrebonne Parish Consolidated Government (T.P.C.G.)
    Public Works - Pollution Control

  • Problem in sending file thru sockets

    Hello
    i am sending a file thru sockets....the file reaches the server but there is loss of file contents. i do not recieve the entire file. whats wrong?
    my Server code
    //package socket_try ;
    // SimpleServer.java: a simple server program
    import java.net.*;
    import java.io.*;
    import javax.comm.*;
    import java.util.*;
    public class Server
    public static final int BUFFER_SIZE = 1024 * 50;
    static CommPortIdentifier portId;
    static Enumeration portList;
    SerialPort serialPort;
    Thread readThread;
    public static void main(String[] ar)
    byte[] buffer;
    buffer = new byte[BUFFER_SIZE];
    int port = 6666; // just a random port. make sure you enter something between 1025 and 65535.
    boolean portFound;
    try
    ServerSocket ss = new ServerSocket(port); // create a server socket and bind it to the above port number.
    System.out.println("Waiting for a client...");
    Socket socket = ss.accept(); // make the server listen for a connection, and let you know when it gets one.
    System.out.println("Got a client :) ... Finally, someone saw me through all the cover!");
    System.out.println();
    BufferedInputStream bin = new BufferedInputStream(socket.getInputStream());
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("c:\\SMS.txt"));
    int in;
    try
    int len = 0;
              while ((len = bin.read(buffer)) > 0) {
                   bos.write(buffer, 0, len);
                   System.out.print("#");
              bin.close();
              bos.flush();
              bos.close();
              socket.close();
    ss.close();
    catch(Exception x)
    x.printStackTrace();
    catch(Exception e)
    System.out.println("Exception : "+e);
    my client code
    import java.net.*;
    import java.io.*;
    public class Client
    public static final int BUFFER_SIZE = 1024 * 50;
    public static void main(String[] ar)
    int serverPort = 6666; // make sure you give the port number on which the server is listening.
    String address = "192.168.1.3"; // this is the IP address of the server program's computer. // the address given here means "the same computer
    as the client".
    int in=0;
    byte[] byteArray;
    byte[] buffer;
    buffer = new byte[BUFFER_SIZE];
    try
    InetAddress ipAddress = InetAddress.getByName(address); // create an object that represents the above IP address.
    System.out.println("Any of you heard of a socket with IP address " + address + " and port " + serverPort + "?");
    Socket socket = new Socket(ipAddress, serverPort); // create a socket with the server's IP address and server's port.
    System.out.println("Yes! I just got hold of the program.");
    // Get the input and output streams of the socket, so that you can receive and send data to the client.
    // Just converting them to different streams, so that string handling becomes easier.
    BufferedInputStream bis;
    BufferedOutputStream bos;
    bis = new BufferedInputStream(new FileInputStream("c:\\send.txt"));
    bos = new BufferedOutputStream(socket.getOutputStream());
    byte[] receivedData;
    int len = 0;
    while ((len = bis.read(buffer)) > 0)
    bos.write(buffer, 0, len);
    System.out.print("#");
         for(int y =0 ; y < buffer.length ; y++)
    char s =(char) buffer[y];
    System.out.println("character:"+s);
    bis.close();
    bos.flush();
    bos.close();
    socket.close();
    System.out.println("\nDone!");
    catch(Exception x)
    x.printStackTrace();
    } /* end of main */
    }/* end of class */
    what is wrong can please anyone tell me??????

    As I don't know how long a record is, that's not a very useful answer. How many bytes are you expecting and how many do you actually get?

  • Connecting to localhost through socket

    Hi Friends
    I want to connect to the localhost (wamp server) and need to read the video file byte by byte through socket please help me to find out the solution.
    Thanks
    Sam

    Turn off your Firewall
    wamp use generally the port 80
    Can you tell more about your problem?

Maybe you are looking for