A
A
Alexander Wolf2016-05-31 17:40:06
JavaScript
Alexander Wolf, 2016-05-31 17:40:06

Which is faster: websocket or "regular" connection?

Good afternoon, comrades!
We upload files to the server using xhr. Now we just read the file (be it FileReader or FormData) and upload it to the server via XMLHttpRequest.
However, our entire site is built on websocket. Maybe it would be wiser to send everything through sockets? Or will it take too long / pitfalls / etc?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Puzynya, 2016-05-31
@mannaro

I think the only problem will be dealing with other protocol messages while you are transferring the file. Haven't worked with websockets for a long time, but something tells me that file transfer will block other messages on the channel. If this is critical for you, you have two ways to solve the problem:
1. Transfer the file in parts.
2. Transfer the file through another channel. Such a channel can be a separate socket or, attention, xhr
If my assumption about a blocked channel is wrong, then I can’t think of other pitfalls.
Remember that the http protocol has already taken care of the file transfer format for you (remember multipart / form-data as one of the solutions), in sockets you will create a bicycle.

R
Rou1997, 2016-05-31
@Rou1997

A "normal" connection is the HTTP protocol, it is also based on TCP / IP, but in order to receive a response from the server, you first need to make an HTTP request, this is a load on both the client and the server, and WebSockets is almost "raw" TCP/IP, the connection remains open, there are no "requests" and "responses", both sides send packets when they "please", so WebSockets is better suited for push notifications, for example, instant messages (chats), in other cases it does not makes no sense.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question