Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket programing vs. web service? [closed]

Tags:

I want to create a Mobile messaging service, but I don't know which is better to use a socket programming or a web service ?.

What are the concerns that I need to take in consideration when creating such service ? such as cost of connection .. etc.

If you need more details just tell me before voting the question down or to be closed !

like image 731
Adham Avatar asked Aug 30 '11 00:08

Adham


People also ask

What is difference between socket and service?

2 Answers. Show activity on this post. A web service is an HTTP server that responds to client SOAP/REST/JSON requests. A web socket is a client-side API that allows a web browser to create a bidirectional communication link with a server without having to change/reload the current page.

Is WebSocket better than REST?

WebSocket approach is ideal for real-time scalable application, whereas REST is better suited for the scenario with lots of getting request. WebSocket is a stateful protocol, whereas REST is based on stateless protocol, i.e. the client does not need to know about the server and the same hold true for the server.

What is difference between socket and WebSocket?

WebSocket is a protocol, Socket is an endpoint - got it thanks. Also, a simple google search returned "The current API specification allowing web applications to use this protocol(WebSocket) is known as WebSockets" (note the plural).

Is socket programming still used?

Most current network programming is done either using sockets directly, or using various other layers on top of sockets.


1 Answers

Webservices are generally speaking "easier" to do, thanks to the tremendous interest in them and the support for them in developer tools and through libraries and frameworks.

However, especially if your payload is small (think messages the size of a typical SMS or tweet), the overhead you create with webservices is prohibitive: bytes sent over a wireless network like GPRS or UMTS are still very expensive, compared to bytes carried over cable or ADSL. And web services carry several layers of invisible info around that the end customer will also have to pay.

So, if your use case is based on short messages, I'd at least advise to do some bandwidth simulation calculations, and base your decision on bandwidth savings vs increased complexity of your app.

While looking at sockets, also have a look at UDP: if you can live with the fact that basically you throw someone a packet, and without designing some ack mechanism into your protocol you'll never be sure the message arrived, it's very efficient because there is no traffic to create and maintain a connection, and even pretty long messages can very well be transported inside 1 UDP packet.

EDIT based on comment:

  • stream socket: not sure how you define streams, but streams and messages are two very distinct concepts for me, a stream is a typically longer sequence of data being sent, whereas a message is an entity that's sent, and optionally acknowledged or answered by the receiver.
  • bandwidth simulation: the easiest way to understand what I'm talking about is to get Wireshark and add up everything that gets transported across the net to do a simple request of a very short string - you'll see several layers of administrative info (ie invisible, just there to make the different protocol layers work) that are all traffic paid for by the end user. Then, write a small mock service using UDP to transport the same message, or use a tool like netcat, good tutorial here, and add up the bytes that get transported. You'll see pretty huge differences in the number of bytes that are exchanged.

EDIT2, something I forgot to mention: mobile networks used to be open, transparent networks with devices identified by public IP addresses. There's a rapid evolution towards NATed mobile networks which has its impact on how devices inside and outside this "walled garden" can communicate (NAT traversal). You'll need to take this into account when designing your communication channel.

As for the use of streams for a chat application: it offers some conceptual advantages, but you can very well layer a chat app on top of UDP, look here or here

like image 143
fvu Avatar answered Feb 24 '23 02:02

fvu