Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6693367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:58:29+00:00 2026-05-26T05:58:29+00:00

Possible Duplicate: how to implement TCP server and TCP client in java to transfer

  • 0

Possible Duplicate:
how to implement TCP server and TCP client in java to transfer files

I write application which will send files to server through socket. Its very important to all files came correct from client to server with no errors, lost data and other like that. To do that I need to use TCP protocol I think but I dont know how to do that. Is socket in Java is default using TCP. If not how can I send data through TCP? Thanks for any help and tip.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:58:29+00:00Added an answer on May 26, 2026 at 5:58 am

    And here’s a good example from this thread Java TCP socket: data transfer is slow

    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    public class Transfer {
    
        public static void main(String[] args) {
            final String largeFile = "/home/dr/test.dat"; // REPLACE
            final int BUFFER_SIZE = 65536;
            new Thread(new Runnable() {
                    public void run() {
                            try {
                                    ServerSocket serverSocket = new ServerSocket(12345);
                                    Socket clientSocket = serverSocket.accept();
                                    long startTime = System.currentTimeMillis();
                                    byte[] buffer = new byte[BUFFER_SIZE];
                                    int read;
                                    int totalRead = 0;
                                    InputStream clientInputStream = clientSocket.getInputStream();
                                    while ((read = clientInputStream.read(buffer)) != -1) {
                                            totalRead += read;
                                    }
                                    long endTime = System.currentTimeMillis();
                                    System.out.println(totalRead + " bytes read in " + (endTime - startTime) + " ms.");
                            } catch (IOException e) {
                            }
                    }
            }).start();
            new Thread(new Runnable() {
                    public void run() {
                            try {
                                    Thread.sleep(1000);
                                    Socket socket = new Socket("localhost", 12345);
                                    FileInputStream fileInputStream = new FileInputStream(largeFile);
                                    OutputStream socketOutputStream = socket.getOutputStream();
                                    long startTime = System.currentTimeMillis();
                                    byte[] buffer = new byte[BUFFER_SIZE];
                                    int read;
                                    int readTotal = 0;
                                    while ((read = fileInputStream.read(buffer)) != -1) {
                                            socketOutputStream.write(buffer, 0, read);
                                            readTotal += read;
                                    }
                                    socketOutputStream.close();
                                    fileInputStream.close();
                                    socket.close();
                                    long endTime = System.currentTimeMillis();
                                    System.out.println(readTotal + " bytes written in " + (endTime - startTime) + " ms.");
                            } catch (Exception e) {
                            }
                    }
            }).start();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to programmatically send SMS on the iPhone? I want to implement
Possible Duplicate: Efficient way to implement singleton pattern in Java I was reading this
Possible Duplicate: Reliable and fast FFT in Java i want to implement a fast
Possible Duplicate: What C++ library should I use to implement a HTTP client? What
Possible Duplicate: Bayesian networks in MATLAB Is there a toolbox in Matlab which implement
Possible Duplicate: Implement linked list in php We can make link list in Java,
Possible Duplicate: How to implement licensing in php downloadable application I am developing a
Possible Duplicate: How do you implement a good profanity filter? I am developing a
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: A comprehensive regex for phone number validation Greetings, I need to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.