in Education by
I want to send files asynchronously. I got on sending a file client->server->another client, but if i want to send a very big file, the client can't send any other commands to server until the file is totally sent. For every file client wants to send, i create a new thread in which i'll read 1kb of the file at a time and sending to the server, then the server will receive the 1kb and send further to the desired client. The problem is that when the client sends the file, the socket is full with bytes from server. I should make one client-server socket for every file i want to send? I've tried everything but nothing was a success. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Creating dedicated sockets for each transfer is one solution, and it's not a bad one unless the number of simultaneous connections is large (only so many IP ports are available on a system, and the server will need twice as many). Threads don't simplify this as much as you might think, and introduce their own challenges; select is a simpler way to efficiently transfer data on multiple sockets from a single thread/process. It works by exposing the underlying operating system's knowledge of which sockets are ready for reading and writing to the program. The challenge for you with the multi-socket approach, regardless of threading choices, is that the server will have to tell the recipient to open a new connection back to the server for each new transfer. Now you need a command mechansim to tell the recipient to open a new connection for the next file. Another option would be to open only one socket, but send multiple files simultaneously over the socket. You might accomplish this by sending a data structure containing the next parts of each file instead of simply streaming the file directly. For example, you might send a message that looks something like this (rendered in JSON for clarity, but it would be a valid transport format): [ { "name": "file.txt", "bytes": "some smallish chunk of content", "eof": false }, { "name": "another.txt", "bytes": "chunk of another.txt content", "eof": true } ] This example is of course naively simplistic, but hopefully it's enough to get the idea across: By structuring the messages you're sending, you can describe to which files, which chunks of bytes belong, and then send multiple chunks of multiple files at once. Because of your client->server->client approach, this seems like the best path forward to me.

Related questions

0 votes
    I want to send files asynchronously. I got on sending a file client->server->another client, but if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I am working on my first Android Application. What I am trying to do is a POST request to a REST ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am using jersey, and I want to send (in a POST) a list of objects to the server. This is ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    Choose the RDBMS which supports full fledged client server application development (a) dBase V (b) Oracle 7. ... topic in chapter Storage and File Structures of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    Write program to send username to server and server will send helloto clint using udp Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    write a program to evaluate the arithmetic statement. X=A-B+C*(D*E-F)/G+H*K a) Using a general ... zero -address operation instruction. Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    I want to change a couple of files at one time, iff I can write to all of them. I'm wondering if I ... to this problem look like? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How can you send data using a Worker object? (a) postMessage() (b) sendMessage() (c) Message() ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    I have a CKEditor in my page. Like this Facelet Title function comeBack(){ document.getElementById(editorValue ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I have a CKEditor in my page. Like this Facelet Title function comeBack(){ document.getElementById(editorValue ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    The idea is to create server in master process, and handle requests in workers. I want to utilize all ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    If a client sends an XML request to a server, can we ensure that the communication remains confidential?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    Which directive of Cache Control Header of HTTP response indicates that resource is cachable by only client and server, no intermediary can cache the resource?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    I am learning about OAuth2 and OpenID Connect by experimenting with ASP.NET Core and IdentityServer4. So far ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 21, 2022 in Education by JackTerrance
0 votes
    Using email hacking illicit hackers can send & spread ___________ virus _____________ and spam emails. (a) ... -Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Nov 1, 2021 in Education by JackTerrance
...