#socket connection and threading within python

65 messages · Page 1 of 1 (latest)

fluid hollow
#

I need help implementing socket connection in python. I have a base code which allows for one connection, and multiple connections without threading. I how can I implement threading?

distant horizon
#

Sure you can come up with something after reading this.

fluid hollow
#

Thanks I'll give it a read

#

Keep this thread open

fluid hollow
#

that is complex

distant horizon
#

You should make simpler stuff before than jumping to your goal too quickly

fluid hollow
#

im trying to wrap my head around it

#

i dont know if its neccesary for all those functions

distant horizon
#

T.tag projects

tropic mauveBOT
#

Tim started a series covering beginner python projects recently, see that here https://www.youtube.com/watch?v=7R-CfL21zIY for more project ideas type "t.tag project 1" in #bot-commands without the quotes (there are 8 projects as of now, "t.tag project 2", etc.). There will not be a premade project for everything so I recommend trying to think of something you want to do and coming up with your own projects that will teach you. There are also coding practice websites you can find on google with small example problems for practice. We also host weekly coding challenges and code jams here, see #challenge for the weekly challenges and #code-jams for the code jams.

distant horizon
#

One of them is on threading as far as i remember.

fluid hollow
#

im watching the video now

#

the thing im trying to do is have socket connection handled by threads

#

is a new thread required for each new connection?

#

how to spawn a new thread

#

when a new connection connects to server

#

tim made a video on sockets and threads but it was only 1 thread

#

which is somewhat right because only 1 thread can run at one time

distant horizon
#

@fluid hollow can u send the code if u dont mind

#

Ig u can just create several thread instances and start them?

#

Not sure cuz i havent tinkered with it but i have seen others' code and sorta be like this

fluid hollow
distant horizon
#

Shoot sry to bother but

#

T.tag paste

tropic mauveBOT
distant horizon
#

Can u send it on one of these

#

Cuz i am on mobile

#

And i wont download codes

fluid hollow
#

yea no worries

#

server

#

client

distant horizon
#

Giving 404 error

distant horizon
#

Not found actually

fluid hollow
#

that should work now

#

sever client

#

so to build on the communication i have another file which implements file download and upload

distant horizon
#

So you want

#

Like everytime it connects you want to still being able to input

#

Not possible, but you can probably uhhh use a function

fluid hollow
#

I want only the server to send commands out and for clients to respond to those commands accordingly

distant horizon
#

You enter info first. And then connect all in the same time

fluid hollow
#

i got it done with just 1 client

distant horizon
#

Then what are threads for

fluid hollow
#

i dont know really

#

for the functions

distant horizon
#

Threading concept in a simple way to say, its running things at the same time. So see where you need this

fluid hollow
#

threading runs concurrently

#

only 1 thread per core

distant horizon
#

Wrong

fluid hollow
#

thats what he said in video

distant horizon
#

Threading: parallelism
Async: concurrency

#

I guess

#

@fluid hollow anyway

#

This is a hard concept, even to me, so nvm

fluid hollow
#

watch the video in bot commands

#

i went on to his 2nd video