Questions on Device-to-Computer Communication

I’ve searched for this everywhere, but I can’t find anything that gives basic information - I’ve never been a web developer, and “client”, “server”, “socket”, and such make me confused… Nowhere could I actually find the definition of “client”, “server”, or “socket” (along with a host of other network-related words).

Basically what I’d like to do is send a message from a device to a computer near-instantaneously. I would really not like someone just to hand me a solution, though - I’d like to actually “get” how to do it.

I read this by Rob Miracle, and saw that what I wanted was somehow connected with a “socket”, but… I still don’t know what that means, because he just went into the other two options - saying that “socket” was too low-level for most people (uh oh - am I “most people”…?).

I’d still like to try, though - if I could get a socket library that communicates with a computer working, that would be awesome. Any pointers?

Any help is appreciated :slight_smile:

  • Caleb

You can experiment with Noobhub. http://developer.coronalabs.com/code/noobhub 

It seems I got the terminology wrong - that looks great, but what I’m looking for is to connect over the Wireless, not the internet… Does Noobhub do that too?

  • C

Ah ok, haven’t used that myself, but maybe AutoLAN then?  http://developer.coronalabs.com/code/autolan

Server - a central computer that multiple people/apps/other computers/devices can connect to to exchange data. It’s usually always on and reachable by anyone allowed to.

Client - any computer / device / app / person attempting to connect to said server. In the mobile app world your device / app is usually the client.Though in Peer-to-peer communications your device/app could become a server if you let other devices connect to you.

All Internet based communications between computers uses sockets. Think of them as a pipe. Your client opens a connection to a specific port on the server where the service you want to access is listening.

Once this connection (a socket) is established, data can begin flowing between the computers (your device is a computer for the remainder do this post) Some things like connecting to web services, like the REST services I talked about use sockets, but the service has been abstracted so that you don’t have to worry about the socket level programming (and relative to Lua and Corona, it’s pretty low level stuff).

In other words way under the hood network.request() opens a socket to port 80 of a web server, transmits some data, reads the resulting data the hangs up (closes the socket). Web services are designed to work for short lived, large one-time data dumps.

There is a lot of overhead to make that socket connection and the open and close model of the web doesn’t allow for high speed, low latency communications. It Is great to fetch your Facebook friends or update your twitter status, but your not going to do Call of Duty multiplayer that way.

For those types of games you have to have a server where you can have a program run all the time (also referred to as a server. Think of a software server running on the hardware server). The game server runs all the time and listens for incoming socket connections. But unlike web services, the client and server keep the socket open and exchange small bursts of data called packets.

The server looks at the packet and processes it, enforcing game rules or forwarding it to other players in the same game. The server can generate messages to any or all of the attached clients. Your client of course has to accept the inbound packets/messages and do with them what ever your game requires of it. When the game is over or your player quits, then the socket gets cleaned up and closed.

Sockets are not endless (limited amounts) so you have to mange it as a resource too. Hope that helps explain things in a general fashion.

Rob

(EDIT: Interesting, I entered this on my iPad and it lost all the paragraph breaks… Edited to break the text back up)

(EDIT2: Fix the autocorrects and typos)

^^ great post above outlining a lot of information in a very nice summary. 

PS. I also noticed the same issue on my iPad. Running IOS 7 if that helps troubleshoot in any way. Sorry for the off-topic feedback.

@Rob Miracle:

Wow, great post! That cleared a lot up and raised a lot of the mist from the mysterious world of Clientserversocket :slight_smile:

I think I’ll look into AutoLAN, to see what I can see. I’ll let everyone know what comes of it.

  • C

You can experiment with Noobhub. http://developer.coronalabs.com/code/noobhub 

It seems I got the terminology wrong - that looks great, but what I’m looking for is to connect over the Wireless, not the internet… Does Noobhub do that too?

  • C

Ah ok, haven’t used that myself, but maybe AutoLAN then?  http://developer.coronalabs.com/code/autolan

Server - a central computer that multiple people/apps/other computers/devices can connect to to exchange data. It’s usually always on and reachable by anyone allowed to.

Client - any computer / device / app / person attempting to connect to said server. In the mobile app world your device / app is usually the client.Though in Peer-to-peer communications your device/app could become a server if you let other devices connect to you.

All Internet based communications between computers uses sockets. Think of them as a pipe. Your client opens a connection to a specific port on the server where the service you want to access is listening.

Once this connection (a socket) is established, data can begin flowing between the computers (your device is a computer for the remainder do this post) Some things like connecting to web services, like the REST services I talked about use sockets, but the service has been abstracted so that you don’t have to worry about the socket level programming (and relative to Lua and Corona, it’s pretty low level stuff).

In other words way under the hood network.request() opens a socket to port 80 of a web server, transmits some data, reads the resulting data the hangs up (closes the socket). Web services are designed to work for short lived, large one-time data dumps.

There is a lot of overhead to make that socket connection and the open and close model of the web doesn’t allow for high speed, low latency communications. It Is great to fetch your Facebook friends or update your twitter status, but your not going to do Call of Duty multiplayer that way.

For those types of games you have to have a server where you can have a program run all the time (also referred to as a server. Think of a software server running on the hardware server). The game server runs all the time and listens for incoming socket connections. But unlike web services, the client and server keep the socket open and exchange small bursts of data called packets.

The server looks at the packet and processes it, enforcing game rules or forwarding it to other players in the same game. The server can generate messages to any or all of the attached clients. Your client of course has to accept the inbound packets/messages and do with them what ever your game requires of it. When the game is over or your player quits, then the socket gets cleaned up and closed.

Sockets are not endless (limited amounts) so you have to mange it as a resource too. Hope that helps explain things in a general fashion.

Rob

(EDIT: Interesting, I entered this on my iPad and it lost all the paragraph breaks… Edited to break the text back up)

(EDIT2: Fix the autocorrects and typos)

^^ great post above outlining a lot of information in a very nice summary. 

PS. I also noticed the same issue on my iPad. Running IOS 7 if that helps troubleshoot in any way. Sorry for the off-topic feedback.

@Rob Miracle:

Wow, great post! That cleared a lot up and raised a lot of the mist from the mysterious world of Clientserversocket :slight_smile:

I think I’ll look into AutoLAN, to see what I can see. I’ll let everyone know what comes of it.

  • C