Page 1 of 1

Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 10:40 am
by crow
{Missing}
Hey there all'
{Missing}

anyone ok of a good please to read up on tuts about this? coroutines really confusers me but I need to make a client that is also the server like a p2p where
the user logins in there IP is loged a friend logs in that IP is loged then the 2 can connect without the server once both saids as the IP's I want to make a text
based game that will still work in the future when the main host is dead/down or just no longer offering the user login as it will have a manual connect also, this wont be made in love but it is made in lua so if anyone as any tuts they know of to help out it be great

coroutines really makes me gets to my head I tried using it many times and failed lol :shock:

Edit:
Old
anyone ok of a good please to read up on tuts about this?
new
As anyone got any good places to read up on tuts about this?

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 11:25 am
by Robin
Do you want resources on how to use luasocket with coroutines, or both resources on luasocket and resources on coroutines, separately?

As for the long question without any punctuation, to connect you need to know what to connect to, so I guess what you want to do is use the host to give the clients contact information of the others, so they can set up individual connections, but this seems rather tricky to get right in my untrained eyes.

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 11:27 am
by vrld
crow wrote:anyone ok of a good please to read up on tuts about this?
Chapter 9 (especially part 9.4) of the PIL.

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 12:12 pm
by crow
Robin wrote:Do you want resources on how to use luasocket with coroutines, or both resources on luasocket and resources on coroutines, separately?
Well if you know tuts on both just link them sure they would help and sure it will help others also.
Robin wrote: As for the long question without any punctuation,
Robin your getting rude now and downgrading please don't bring it up again its unfair yes I have learning problems you said you peace more then once now leave it out please, I had to redo this about 5 time as you really got on my tit on this one.
Robin wrote: to connect you need to know what to connect to, so I guess what you want to do is use the host to give the
clients contact information of the others, so they can set up individual connections, but this seems rather tricky to get right in my untrained eyes.
vrld wrote:
crow wrote:***
Chapter 9 (especially part 9.4) of the PIL.
Thats using HTTP but I give the hole thing a read I sure this will be useful also thanks vrld
PHP would handle the users and the IP address to connected to thats not a problem and there would also be a direct connect option where if you know your friends IP to connect to

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 1:08 pm
by Robin
Maybe the luasocket introduction and reference would help?.
crow wrote:
Robin wrote: As for the long question without any punctuation,
Robin your getting rude now and downgrading please don't bring it up again its unfair yes I have learning problems you said you peace more then once now leave it out please, I had to redo this about 5 time as you really got on my tit on this one.
Okay. I was trying to help you, but if it is unwanted or doesn't work for you, I'll stop.

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 1:25 pm
by leiradel
If you want to use coroutines to prevent your app from blocking when sending/receiving things over the network then it won't work. Coroutines are a kind of cooperative multitask, so if one coroutine blocks the entire app blocks.

To prevent a network connection from blocking you'll need either socket.select or Lua threads.

Cheers,

Andre

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 2:17 pm
by vrld
leiradel wrote:If you want to use coroutines to prevent your app from blocking when sending/receiving things over the network then it won't work.
Only half of the truth. You can use nonblocking network IO using a timeout of 0. Like chapter 9.4 of the PIL demonstrates.

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 2:31 pm
by leiradel
vrld wrote:Only half of the truth. You can use nonblocking network IO using a timeout of 0.
That's correct, sorry for not mentioning it.

EDIT: Since there are three possible solution to the blocking IO issue, I think my post qualifies for 2/3 of the truth :awesome:

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 2:54 pm
by Robin
vrld wrote:
leiradel wrote:If you want to use coroutines to prevent your app from blocking when sending/receiving things over the network then it won't work.
Only half of the truth. You can use nonblocking network IO using a timeout of 0. Like chapter 9.4 of the PIL demonstrates.
Still, you cannot use coroutines for that purpose.

You can use nonblocking IO to prevent from blocking, but coroutines don't do anything about that. To say you can use coroutines to prevent your app from blocking is like saying you can use PO2 images to prevent your app from blocking: sure, if you use coroutines/PO2 images and an actual solution it'll work, but the same will happen if you don't use coroutines/PO2 images.

Re: Lua + Sockets + coroutines

Posted: Wed Mar 23, 2011 5:47 pm
by crow
I will be making this in AMS and the exe does not offer threads I hear coroutines or Lans can offer lua like threads. Coroutines could be wrong thing to use I just been reading the ways to have it to work :)

I have a way to do it a simple way but its not a free way that offers sockets that don't lock up but luasockets will make it easyer for people to port to another OS.

thanks guys i still reading anyone know of a dedicated p2p script in lua ?