Lua + Sockets + coroutines

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
crow
Party member
Posts: 186
Joined: Thu Feb 24, 2011 11:47 pm
Location: UK
Contact:

Lua + Sockets + coroutines

Post 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?
Last edited by crow on Wed Mar 23, 2011 12:18 pm, edited 1 time in total.
Sir Kittenface
Möko IDE Codename (Erös) Returns Soon

I am dyslexic so if any of my replys confusing please just ask me to reword it as this will make things a lot easier for all parties lol.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua + Sockets + coroutines

Post 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.
Help us help you: attach a .love.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Lua + Sockets + coroutines

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
crow
Party member
Posts: 186
Joined: Thu Feb 24, 2011 11:47 pm
Location: UK
Contact:

Re: Lua + Sockets + coroutines

Post 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
Sir Kittenface
Möko IDE Codename (Erös) Returns Soon

I am dyslexic so if any of my replys confusing please just ask me to reword it as this will make things a lot easier for all parties lol.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua + Sockets + coroutines

Post 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.
Help us help you: attach a .love.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Lua + Sockets + coroutines

Post 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
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Lua + Sockets + coroutines

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Lua + Sockets + coroutines

Post 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:
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua + Sockets + coroutines

Post 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.
Help us help you: attach a .love.
User avatar
crow
Party member
Posts: 186
Joined: Thu Feb 24, 2011 11:47 pm
Location: UK
Contact:

Re: Lua + Sockets + coroutines

Post 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 ?
Sir Kittenface
Möko IDE Codename (Erös) Returns Soon

I am dyslexic so if any of my replys confusing please just ask me to reword it as this will make things a lot easier for all parties lol.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest