#networks

1 messages ยท Page 18 of 1

gloomy root
#

And c is only quicker because its native and compiled

tall olive
#

It enabled that but you don't know the way to make it higher perf yet geblobderpy

gloomy root
#

But also brings alot of danger with it

quick knoll
#

I think there is value in struggling with sockets once

#

because afterwards you know what you are doing

tall olive
#

It's great to know how they work for sure

quick knoll
#

and I know that it sucks

undone gust
#

and I know that it sucks
@quick knoll im having fun dealing with bugs and errors

#

lots of it

tall olive
#

Tcp is annoying to write protocols on top of as well

quick knoll
#

we all did when we started working with sockets

undone gust
#

hey guys wanna do a funny test

#

i want to see how many concurrent clients my laptop can handle (normal clients, none of that 3k char long shit, especially because i just filter it if it's too long)

ember ledge
#

my pc freezed after 2-3 clients lol

#

just because of threading

undone gust
#

if you enter a normal message it just gets printed to the server so it's kind of like a one sided chatroo, but i can just stream it so we can have some fun ๐Ÿ˜„

gloomy root
#

A single threaded server done right should be able to handle about 5k req a sec easily

undone gust
#

WHAT

#

THE

#

FUCK

ember ledge
#

XDDDDD

quick knoll
#

a single threaded python server

undone gust
#

how can you handle more than 1 client with a single thread

#

like literally how does that work

tall olive
#

Async

gloomy root
#

My my WSGI server will go to 11k a sec per thread but that's about as far as it goes

ASGI will go to about 30k per thread

quick knoll
#

there are different ways of achieving concurrency

#

threading is one way, but has lots of issues ( like not being threadsafe, huh)

undone gust
#

My my WSGI server will go to 11k a sec per thread but that's about as far as it goes

ASGI will go to about 30k per thread
@gloomy root in what instance do you even need to handle this many "messages"

gloomy root
#

Production

tall olive
#

Imagine discord

quick knoll
#

Production
@gloomy root ๐Ÿ˜†

undone gust
#

discord probably has a shit ton of servers

tall olive
#

Less than you might think

undone gust
#

tha's off point tho

#

Less than you might think
@tall olive i'm guessing 50

gloomy root
#

The more efficient a server is the less server specs you need to run a system

undone gust
#

50 good servers

tall olive
#

More than you might think then. Haha

gloomy root
#

Discord is serverless

undone gust
#

o.O

tall olive
#

No it's not

quick knoll
#

goood

undone gust
#

how could it even be

quick knoll
#

"serverless"

#

no such thing

gloomy root
#

By server less I don't mean not running on a pc

#

I mean the deployment type obs

tall olive
#

Discord is not serverless

gloomy root
#

Is it not?

tall olive
#

It runs on autoscaling managed instance groups at least for stateless stuff

gloomy root
#

Is the backend still python and flask (I'm not sure about the flask thing)

undone gust
#

oh that kinda stuff, yeah yeah i get it

tall olive
#

Yea it's flask and gevent

#

For api

gloomy root
#

Ah fair enough

tall olive
#

But also a lot of elixir and rust

gloomy root
#

Elixir for ws?

tall olive
#

For most of the chat infra

#

Python is for the api

gloomy root
#

Fair enough, what made you guys choose WSGI vs ASGI systems?

#

Flask v other async systems

tall olive
#

Was py2 until recent

gloomy root
#

Would you guys ever move to ASGI or just keep it with gevent and flask

tall olive
#

I imagine the stack was chosen for familiarity by the original devs and then momentum

#

No big plans to change right now because it works great right now

gloomy root
#

Ig back then flask and django were some of the few frameworks around and no asgi

quick knoll
#

wait, you work for discord gary?

gloomy root
#

Ye Gary staff

tall olive
#

Yea on the backend infra

gloomy root
#

Does gevent get heavy affected by things like requests

tall olive
#

Not product so I can't answer anything about that geblobnervous

quick knoll
#

infra is more interesting anyway

gloomy root
#

Tho I imagine you guys don't need any client req

tall olive
#

We have rpc libs that work with gevent for internal rrquests

gloomy root
#

Oh nice

tall olive
#

I only mention the product disclaimer to fend off product questions/complaints geblobderpy

gloomy root
#

People always lurking :P

tall olive
#

I just like python and this server is managed in a way that's not overwhelming to pop in and help

gloomy root
#

Topic channels are pretty calm at times

tall olive
#

Haha was going to say except one

gloomy root
#

What sort of performance so you guys get out of gevent compared to asyncio BTW

tall olive
#

Haven't compared. Would be a huge change

gloomy root
#

I've messed around with libuv and pyuv but not had it get anywhere close to asyncio

tall olive
#

Reality doesn't really match benchmarks. Most slow down is waiting on rpc/databases/network

gloomy root
#

Only as fast as the slowest component

tall olive
#

The value of async is more concurrency while blocking on io

gloomy root
#

Is discord Sql or no sql?

tall olive
#

Both

#

Depends on the data

gloomy root
#

Wasn't it a fork or mongo for one of them

#

Fork of*

tall olive
#

Tokumx. Not anymore

#

Moved a lot of stuff to scylla

gloomy root
#

What made you guys move?

tall olive
#

A bit of consolidating on fewer technologies and a bit of preferring the scalability and performance model

gloomy root
#

Scylla looks pretty nice tbh

#

Reminds me of datomic a bit

restive blaze
#

Cassandra still kicking or is that blog article obsolete?

tall olive
#

we have one cassandra cluster left

#

most is moved off

restive blaze
#

got it, Scylla is drop in replacement

tall olive
#

yeah for the most part

#

but with more consistent performance and more isolated failures

restive blaze
#

haven't used it so TIL

#

work is all either MSSQL Always On Clusters or CosmosDB

undone gust
#

@tall olive @quick knoll sorry for the bad ping, i'd like to see if the server works as it should with multiple users from all around and possibly try to break it in every way possible, since i added a sort of chatroom setup the server can see all messages sent (but i havent added that to the client yet), so what i was meaning to ask, if i gave you the client and possibly streamed the chatroom in a vc, would ya like to connect? and maybe break it i guess

#

pinged you two because you're the #networks og's sunglassesvery3dcool

#

uhh actually i can't video stream in this server sadly

tall olive
#

Sorry not available for that

gloomy root
#

@undone gust look at wrk if you want to try break it

#

It's a benchmarking tool that essentially just floods requests at your server

undone gust
#

Niceee

lilac ginkgo
#

Good afternoon! First post on this Discord server so I hope this is the right place to ask.
I am trying to identify the tools I need to write the backend of a real-time "collaborative agenda", where the server will schedule and broadcast events sent from the clients via a web app. Most of the communication between server and clients should be done via websockets (i.e. clients will have their state updated in real time via web sockets or long-polling where a websocket connection is not possible).
My main priorities are performance (hundreds of clients connected simultaneously should be handled seamlessly), caching and database integration.
I have heard of socket.io for Python, which looks promising, but I am not sure of its performances. There is also Django with the recent Channels features.
Any suggestion for my use case?

hexed epoch
#

an easy way to guarantee you have enough server capacity to handle lots of throughput is to just spin up multiple servers, the implementation is pretty agnostic as they'll all be about the same unless you're comparing compiled vs interpreted languages

lilac ginkgo
#

@hexed epoch Hey, thanks for your reply! If performances don't distinguish one implementation over the other, are there other important criteria which in your view would single out 1 or 2 frameworks (possibly including those I mentioned above)? I should mention are we are a small structure of only two devs for now.

hexed epoch
#

I would go with the one that's quickest to get running and easiest to understand when reading/writing the code

lilac ginkgo
#

Cannot be wrong about that :)
So one last question: Do you think there are other promising candidates beside those I mentioned I should consider in in my choice?

ember ledge
#

ay

#
import socket
import time
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


HOST = socket.gethostbyname(socket.gethostname())
PORT = 8888

# Check at the first try
def connect():
    try:
        server.connect((HOST, PORT))
        messages()
    except ConnectionRefusedError:
        print("reconnecting, please wait...")
        time.sleep(0.1)
        connect()

# Check at the second, third, etc.
def reconnect():
    try:
        server1.connect((HOST, PORT))
        messages()
    except ConnectionRefusedError:
        print("reconnecting, please wait...")
        time.sleep(0.1)
        reconnect()
        

def messages():
    while True:
        try:
            command = server.recv(1024).decode()
            print(command)
        except:
            reconnect()

connect()
#

my reconnect function works, the server receives the connection

#

but i got a error: OSError: [WinError 10056]
in 24 line, server1.connect((HOST, PORT))

hexed epoch
#

@lilac ginkgo I don't normally use python for sockets, I typically use Elixir with the Phoenix framework, and it's not too hard

undone gust
#

lets see

lilac ginkgo
#

@hexed epoch Hard to beat the beam vm at this I reckon... I hope my use case allows to stay with Python though. Thanks for the discussion!

undone gust
#

@ember ledge i mean you're using that port for server so i dont think you can also use it for server1

ember ledge
#

i can

undone gust
#

that code is weeeird

vernal surge
#

@lilac ginkgo fwiw, gRPC is what I use for things like this now. They can do bidi streaming

undone gust
#

@ember ledge shouldnt you do server.listen and then connect via the client?

ember ledge
#

bruh

#

i've done it

undone gust
#

no you're doing server.connect

ember ledge
#

server.listen can't be on client

undone gust
#

exactly

#

that's your server code right?

ember ledge
#

client

undone gust
#

i still dont understand why you use 2 sockets, and also why you want to receive commands on the client instead of the server, but the second one i guess isnt too important

ember ledge
#

lol i did it on purpose

#

to receive commands on the client

lilac ginkgo
#

@vernal surge This is an excellent suggestion! I had overlooked gRPC. This seems to allow for a more modular type of development than websockets

#

@vernal surge Is there any gRPC library you'd recommend?

undone gust
#

to receive commands on the client
@ember ledge yeah i see but isn't it better to receive them on the server? that's... kind of the point of servers

vernal surge
#

@lilac ginkgo I've only ever used the ones advertised on gRPC.io

ember ledge
#

i just need it to be like this @undone gust

undone gust
#

anyways i cant exactly pinpoint the error, ill look again later im eating rn

restive blaze
#

if you are targeting businesses, gRPC can annoy net admins

undone gust
#

why do oyu need it to be like that

lilac ginkgo
#

@vernal surge Fair enough. I will need to see if this checks out.

vernal surge
#

@restive blaze all http/3 stuff does lol

ember ledge
#

@undone gust idk, i just want it to be like this XD

undone gust
#

yeah but..

restive blaze
#

but my point is, there is technology and business

#

technology may say "gRPC is best way to go", business may say "Whatever is most compatible with businesses"

#

WebSocket > gRPC when dealing with net admins

undone gust
#

@ember ledge if you do it on the server you can have all commands from all clients in one program and it may be a lil better anyways

ember ledge
#

nevermind lol

vernal surge
#

Depends on what the business is. If the tool is worth the effort, adoption occurs.

lilac ginkgo
#

WebSocket > gRPC when dealing with net admins
@restive blaze You're saying the gRPC means more footwork for consumers of my API / service, if they need to exploit my gRPC in their own ecosystem?

restive blaze
#

j4ng5y, his business idea sounds like Microsoft Teams/Google Chat already

vernal surge
#

@lilac ginkgo the level of effort is different, with gRPC, the client stubs are easily generated

restive blaze
#

I'm saying, bigger businesses with their firewalls may need to poke holes causing poor adoption of your product

#

WebSockets are well known and thus firewalls don't freak out about them

vernal surge
#

I disagree with poking holes. It's all HTTPS, but L7 fws will required things.

restive blaze
#

and it could be WS with clients, gRPC internally

#

gRPC is HTTP/2 which I've seen plenty of firewalls barf on

#

yes yes, businesses should get updated, blah blah blah

#

welcome to business hell

vernal surge
#

@restive blaze only clients I've had using an rpc library of mine didn't have trouble, but yeah, These were tech forward companies

#

Palo Alto / Cisco ASAs

lilac ginkgo
#

@vernal surge @restive blaze I agree with both of you. I am aware that gRPC is not widely adopted among small businesses yet unless they're tech businesses. You've made your case.

restive blaze
#

I'm saying, gRPC is future facing awesome sauce, WebSocket has higher compatibility, I don't know the goal of your software

vernal surge
#

I imagine a PIX would absolutely barf

restive blaze
#

I think Teams/GChat/SLack all use WebSocket for comms

lilac ginkgo
#

Probably they do.

restive blaze
#

WebRTC for Video/Audio

lilac ginkgo
#

Okay folks, I am off to the docs ! Thanks for your help, really appreciated!

vernal surge
#

Biggest trouble I've had with gRPC was when I tried to use it without pre-generating client libraries for an API ... That process is not overly trivial yet I guess

#

So I had to do some gRPC<->JSON magic, but luckily, things like envoy do that for you now

limber shoal
#

Hello guys, i have a question.
Is there a way to transfer a variable/information to my programm by clicking on a link like this.
If yes it would be awesome if someone could explain it to me quick or provide me an explaination on the internet (since i cant find a solution somewhere)

Examples:

http://localhost:5060/quicktask?site=AW-Lab&method=url&input=https://www.aw-lab.com/yeet-AW_846ZJMRC_4045754_19.html

http://dashboard.phasma-aio.com:2001/qt?url=https://www.aw-lab.com/yeet-AW_846ZJMRC_4045754_19.html

Thank you guys very much ๐Ÿ™‚

vernal surge
#

Yeah, you can do that, but you have to be running the web backend to process those @limber shoal

#

But it's fairly trivial to grab request path variables and url parameters with most web frameworks

#

Without knowing what you are doing though, no idea where to direct you

limber shoal
#

@vernal surge Can i write you a DM?

vernal surge
#

Nope

undone gust
#

Nope
damn

vernal surge
#

lol

#

it's less an issue of me getting annoyed, more an issue of "i'm sure there are other who are silent who would benefit from the discussion"

cinder trellis
#

about to start (again) ramping up on Python and VSCODE - any good non-noob tutorials or videos out there? I have a good C programing background.

vernal surge
#

Realpython had some good ones that jump right into things @cinder trellis

cinder trellis
#

Realpython had some good ones that jump right into things @cinder trellis
@vernal surge thanks

wraith grove
#

@cinder trellis The python tutorial is pretty indepth

gloomy root
#

Is someone able to explain how a socket with REUSEADDR load balances on the socket side?

#

Like is it predicable or is it purely down to a random internal system balancing across the multiple processes

clear gate
#

Not 100% certain this is the right help channel but I'm having trouble with aiohttp and my header

#
async def fetch(session, url, params=None):
    global header
    formattedUrl = url #+ '&access_token={}'.format(access_token)
    print(formattedUrl)
    async with session.request('GET', url=formattedUrl, params=params, headers=header) as resp:
        print(resp.status) 
        data = await resp.json()
    return data```
#

so i have this which im trying to request a json with but it requires authentication via access token

#
header = {'Authorization':'Bearer ' + 'redacted, access token here'}```
#

this is what my access token looks like

#

using requests.get() it works just fine with the same url and header

#

but i get a 401 status code using aiohttp

thorn stratus
#

Sniff the traffic and see what's different

#

Also you have a commented out + so there's a line in there that does nothing

clear gate
#

Yeah i know, I was passing it through the url but it was becoming tedious and also not working all the time

thorn stratus
#

Well then how does it get the access token

tiny panther
#

I have 3 antiviruses

#

Avast, Malwarebytes, and Windows Security

#

My computer isn't accepting any incoming connections

#

I tried multiple ports

agile furnace
#

Try to disable something that blocks the connections

tiny panther
#

I'm not disabling my firewall

agile furnace
#

Try to disable features in those 3 antiviruses

tiny panther
#

I think avast is doing it

#

but avast isn't a firewall

thorn stratus
#

You need to the Port on your firewall

#

Is it accepting them on localhost

tiny panther
#

wdym on localhost

#

when I try to connect to the server on the same computer it works

thorn stratus
#

From the own computer to itself

tiny panther
#

yeah oh okay yeah it works

thorn stratus
#

Okay, did you open the port on your firewall

tiny panther
#

No

#

I don't know how

thorn stratus
#

Your on windows right

tiny panther
#

Yes windows 10

thorn stratus
#

Use the search bar at the bottom

#

Type firewall, it'll take you to the firewall controls

#

Then you can make a new rule in incoming rules

tiny panther
#

Okay I'm on t

thorn stratus
#

Configure it to allow all connections on a certain port

tiny panther
#

does port 31607 work

#

Okay it's allowed

#

it's still not connecting

#

Here's my code:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("192.168.x.x", 31607))
s.listen(5)
print("open")

while True:
    # now our endpoint knows about the OTHER endpoint.
    clientsocket, address = s.accept()
    print(f"Connection from {address} has been established.")
    clientsocket.send(bytes("Hey there!!!","utf-8"))```
#

and here is where I connect to it

#
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect_ex(("192.168.x.x", 31607))

while True:
    msg = s.recv(8)
    print(msg.decode())
#

when I try to connect to it on another computer I got Winerror Errno 10060

#

and when I try to connect to it with my phone I get OSError Winerror Errno 107

#

@thorn stratus

gloomy root
#

That is

#

That is not how you bind to an address

regal crane
#

I have question not about python (generally) so im sorry but i dont know any server for stuff like that

#

can anyone help me connect my domain with my page?

undone gust
#

@tiny panther when you do s.bind try to change it to s.bind((socket.gethostbyname(socket.gethostname()), 31607))

#

then on s.connect() in the client put the ip you gey by printing what i just told you, and obviously the port, as a tuple

#

also, send() only takes 1 argument, what to send, you have to do clientsocket.send("Hey there!!!".encode("UTF-8"))

#

and you do s.recv(8) but the message you send is over 8 characters long

#

the argument in recv has to be the length of the message you're receiving

#

in a simple case like this you can just count it by hand, but usually you first send a message long a certain amount which is just spaces and at the end the length, so you always know the length of the first message you send, and then by decoding it you can easily get the length of the message you actually wanted to send

willow swift
#

s.bind(('', 31607)) or s.bind(('0.0.0.0', 31607)) will suffice

vernal surge
#

@regal crane that's pretty easy

#

@regal crane but it also depends on a few things

undone gust
#

wait

#

you can bind to just ''?

#

damnnn

undone gust
#

hey guys how do i send a message to all the clients connected?

ember ledge
#

uh

#

get a list of connections

#

and send all of them in the list

#

idk how to explain lol

undone gust
#

no theres a way to send to all of them at once

#

whatever i did it

tiny panther
#

@undone gust Hmm.. Okay I'll try that

#

it didn't work

#

I'm questioning whether my computer even opens the server

#

Yeah the server does open

#

I tried connecting to it on the same computer

#

everything worked as expected

#

it's just that other devices can't

gloomy root
#

are you actually binding to local host or to external tho

wraith grove
#

You loop through the list and send it to all of them one way or another

tiny panther
#

Idk I'm using my IPv4 address

#

Something is wrong with my comptuer

#

my main one

#

because the code I used worked for a different computer

#

no problem worked super easily

#

What I know is that the server does open

#

so my computer is running a server

#

but when I try to connect to the server from a different device, it doesn't connect

#

When I try to connect from my phone, I get WinError Errno 107

#

and from my other computer I get WinError Errno 10060

#

two different errors

#

(Both my phone and other computer can connect to each other)

#

I've tried connecting my phone to my other computer

#

my main computer can't get those connections but can connect to the server my other computer is running

#

so it doesn't take connections, but can connect, so it works

pure mica
#

Did you try to connect on another network then your own?

#

Maybe its smth with ur network

wraith grove
#

Did you check your firewall

tiny panther
#

I don't know if I did it right but I allowed the port I'm trying to connect too

#

In the inbound part of the firewall

#

the rule

#

My main computer can connect to other networks

wraith grove
#

The difference between the two computers is one is on the same network as you and one isn't?

tiny panther
#

both are on the same network

keen horizon
#

ServerApp is on Comp A and you think it is running a server and exposing a port.

ClientApp is on Comp B (or your phone) and can't connect?

Can you scan Comp A from Comp B to confirm? Is Comp B a *nix machine you can install nmap on? A quick nmap -sS ip.of.comp.a.here will show you ports reachable from outside CompA.

tiny panther
#

Both are Windows machines

tame grove
#

Checked the firewall?

tiny panther
#

I made a rule that allows port 31607 in the inbound section but it made no difference

thorn stratus
#

Can you connect from the computer running the server

tiny panther
#

Yes I can connect to other servers

#

it works when I try to connect to another server

pure mica
#

Yo so got a question. Programs like discord do everything through a server right? So when i send some text in dm to someone. My disc client sends data to the server, which sends the data to the client of the user im dm'ing. So basically is the server the middle man in programs like discord. Is my interpretation right or not?

narrow oak
#

Yeah, it's called client to server architecture. They use webRTC for voices and such but it's mainly a client to server architecture.

pure mica
#

But how does it come people say yea i used wireshark to grab his ip in disc. If they would only be getting the ip adress of the server lol

#

Are those people just stupid and trolling. Or is it in fact possible even with a serverside application

ember ledge
#

As far as I know, wireshare is for packet analysis on the local network. This is all I have ever used it for and if it has another use case I am not aware of it.

pure mica
#

As far as I know, wireshare is for packet analysis on the local network. This is all I have ever used it for and if it has another use case I am not aware of it.
@ember ledge yes, but you can see in wireshark from which ip adress the data is coming.

ember ledge
#

ahh right, right.

undone gust
#

@ember ledge hey how can i check if a client is connected to a certain server with like an if statement?

tall olive
#

Are those people just stupid and trolling
yes

ember ledge
#
import socket
import time
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


HOST = socket.gethostbyname(socket.gethostname())
PORT = 8888

def connect():
    try:
        server.connect((HOST, PORT))
        messages()
    except ConnectionRefusedError:
        print("reconnecting, please wait...")
        time.sleep(0.1)
        connect()

    
def messages():
    while True:
        try:
            command = server.recv(1024).decode()
            print(command)
        except:
            connect()
connect()

i get this error:

  File "C:\Users\Laurynas\Desktop\project\client.py", line 27, in <module>
    connect()
  File "C:\Users\Laurynas\Desktop\project\client.py", line 13, in connect
    messages()
  File "C:\Users\Laurynas\Desktop\project\client.py", line 26, in messages
    connect()
  File "C:\Users\Laurynas\Desktop\project\client.py", line 12, in connect
    server.connect((HOST, PORT))
OSError: [WinError 10056] A connect request was made on an already connected socket```
#

any ideas?

tall olive
#

the error tells you you're connecting on an already connected socket in your messages function

ember ledge
#

so what can i do?

#

close the socket?

tall olive
#

well first, you're doing that an every type of except

#

you probably don't want to reconnect if say you got a unicode decode error

ember ledge
#

do i need to specify the error?

#

bruh im confused

tall olive
#

but when you want to reconnect you need to make a new socket object

ember ledge
#

uh wait

#

ill try

#
# Python program to implement client side of chat room. 
import socket
import time
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

HOST = socket.gethostbyname(socket.gethostname())
PORT = 8888

def connect():
    try:
        server.connect((HOST, PORT))
        messages()
    except ConnectionRefusedError:
        print("reconnecting, please wait...")
        time.sleep(0.1)
        connect()

def reconnect():
    try:
        server1.connect((HOST, PORT))
        messages()
    except ConnectionRefusedError:
        print("reconnecting, please wait...")
        time.sleep(0.1)
        reconnect()
    
def messages():
    while True:
        try:
            command = server.recv(1024).decode()
            print(command)
        except:
            server.close()
            reconnect()
connect()
#

like this?

tall olive
#

no, because nothing is using server1 and that would only let you reconnect on time

ember ledge
#

i can reconnect 1 time

#

and then got an error

tall olive
#

you're not recv on server1 ever

ember ledge
#

because that socket is used

#

oh

tall olive
#

sorry, gotta run but you should just overwrite your server variable with new socket when you need to reconnect

#

probably have to use global server to assign a new socket

ember ledge
#

How would i get the Users IP address? Im making a simple login system in which, an account will be bound to an IP address (IP wuill be hashed) So, they will enter their username, ad if the IP matches the Users Ip it will let them in.

#

uh

#

conn, addr = server.accept()

#

addr[0] is user's IP Address

#

who just connected to the server

waxen kraken
#

I've never worked with HTTP request streaming, but the API I'm using has an endpoint that is a stream. The example from the docs (https://requests.readthedocs.io/en/master/user/advanced/#streaming-requests) has a foreach to loop over the stream, but it doesn't really explain how to work with it other than that. My assumption is that I have to do requests.get(endpoint, stream=True) every second (or how often I want to check if there's something new in the stream) and then do the same procedure they use. Is this correct?

#

And will the response I get then have only the new entries added by the API?

simple flax
#

I have a question regarding architecture of my chat app. Lets say I have multiple rooms and each room has multiple clients. I thought about making a dictionary which is something like {"room id": ["list of all clients"]}. Is this a good approach? So when I want to add a message to a room I need to loop over the list. but my server creates a new thread for each client so will it not be a issue with each thread accessing the same dictionary? especially when a client disconnects and one of the threads needs to modify the list.

regal crane
#

Anyone know how to speed up requests.post? the page itself is very slow but with my internet its even slower

#

i spent 25-27 seconds on sending request

hexed epoch
#

any change in python library would be minuscule compared to the network latency

#

unfortunately, you're at the mercy of your network speed and the speed of the server you're talking to

regal crane
#

but isnt there a way

#

like if i send 5 posts to this page

#

(not a spam bot)

restive blaze
#

depends

#

probably wouldn't help though

regal crane
#

like i mean it could be send in the same time somehow

#

with threading huh

hexed epoch
#

you could try threading them, yeah

regal crane
#

but wont it hurt my pc?

hexed epoch
#

but that won't speed up your network or the server you're talking to

restive blaze
#

would aiohttp help

hexed epoch
#

no, it won't hurt your pc

regal crane
#

o maybe i should try asynchronous

#

thank you guys

#

i will try!

idle portal
#

I've never worked with HTTP request streaming, but the API I'm using has an endpoint that is a stream. The example from the docs (https://requests.readthedocs.io/en/master/user/advanced/#streaming-requests) has a foreach to loop over the stream, but it doesn't really explain how to work with it other than that. My assumption is that I have to do requests.get(endpoint, stream=True) every second (or how often I want to check if there's something new in the stream) and then do the same procedure they use. Is this correct?
@waxen kraken Just follow the example. Call the get just once like this r = requests.get('https://some.url.goes/here', stream=True). Then use for line in r.iter_lines(): to read the streamed reply. One suggestion, and I don't know why they left this out of the example, but iter_lines uses a default chunk_size of 512, but iter_content uses a default chunk_size of just 1, which ends up giving extremely poor performance. I think this is a bug in requests - looking at the source it looks like the intent was to default to CONTENT_CHUNK_SIZE = 10 * 1024. So if you use iter_content, be sure to specify some value for chunk_size, I've used 1024 and it works well. One other point: you will get your HTTP status code from the initial get, probably a 200-299 code. But if there are any server errors while streaming the content, there will be no indication or further exception - your client code will just have to handle bad data if it goes bad.

mellow dock
#

keep the connection open ,buffer the data ,itterate over it

#

clean eh lol

waxen kraken
#

@idle portal But since the example is just a for loop, won't it only read whatever is in the request the first time it is called? Like, I'm thinking about if I consume whatever is in the stream, then I still have to call the request afterwards again to get any new info that was pushed by the API right?

waxen kraken
#

@mellow dock How would I keep the connection open?

gloomy root
#

what

gloomy root
#

That question makes no sense lol

ember ledge
#

Hey folks, I am trying to build a super basic file-uploading API using the Swagger specification and the connexion library. I am new to the multipart/form-data format for files so just wanted to ask if this looks like a reasonable API. Thank you!

openapi: "3.0.0"

info:
  title: File upload API
  version: "1.0"
servers:
  - url: http://localhost:9090/files/v1

paths:
  /files:
    post:
      summary: Upload a new comma-separated file
      operationId: api.post_file
      requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                myFile:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        200:
          description: Upload successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  fileId:
                    type: string
def post_file(myFile):
    fileTitle = myFile.filename
    fileBytes = myFile.stream.read()
    fileDecoded = fileBytes.decode('utf-8')
    file = open("{}/{}".format(UPLOAD_FOLDER, fileTitle), "w+")
    file.write(fileDecoded)
    file.close()
    
    return getFileId(file)
errant bayBOT
#

Hey @ember ledge!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

โ€ข If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

โ€ข If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

gloomy root
idle portal
#

@idle portal But since the example is just a for loop, won't it only read whatever is in the request the first time it is called? Like, I'm thinking about if I consume whatever is in the stream, then I still have to call the request afterwards again to get any new info that was pushed by the API right?
@waxen kraken yes, once you consume the entire stream in the for loop, you'll need to re-call GET to start a new one. Interesting though, if the server just keeps yield ing more data, your for loop won't ever finish. (You may have to handle empty content returned from a call ti iter_lines, and possibly sleep for a second at the bottom of the loop so you are not in a busy loop.)

simple flax
waxen kraken
#

Alright, thanks @idle portal

steady horizon
#

thanks for the warning i guess

copper robin
#

@ember ledge if you have a problem with another user on the server, you're welcome to DM @small mango, otherwise this really isn't the place for that

ember ledge
#

ok thank you

open mulch
#

unless you live on mars, that doesn't make that much sense

#

unless, you have really bad internet

strong laurel
#

does anyone know about encoding and decoding?

#

using json?

stoic pilot
#

hey there everyone! Im trying to learn how to make a website with python but there is something wrong with my code```python

Import and Setup

from flask import Flask

app = Flask(main)

Functions

@app.route("/")
def home():
return "Hello! this is the main page <h1>HELLO<h1>"```

#

error is line 4, in <module> app = Flask(__main__) NameError: name '__main__' is not defined

#

im actually not too familiar with __ main_ _ but im following a tutorial and when the youtuber used it, it didnt show any errors

#

please ping me if you respond

#

also i am using pycharm

ember ledge
#

what python interpreter are you using?

keen edge
#

i think you mean __name__

ember ledge
#

yea that is a good point

#

they go into detail on how to build a basic site

thorn jolt
#

why is it when I use selenium, I get booted off of this site: https://www.yeezysupply.com/ once I click any elements on the page? does anybody have any good resources on website's authentication? (sorry if this is wrong channel)

tidal matrix
#

Noob here, want to create a server-client where client users on a seperate network can send simple text strings to a host machine!

thorn stratus
#

This is about the simplest way to do it

keen edge
#

why is it when I use selenium, I get booted off of this site: https://www.yeezysupply.com/ once I click any elements on the page? does anybody have any good resources on website's authentication? (sorry if this is wrong channel)
@thorn jolt you can't ask for help with sneaker bots, its against rule 5

tidal matrix
#

This is about the simplest way to do it
@thorn stratus Thanks, will try to comprehend that ๐Ÿ˜‚

lusty ermine
#

guys! how can i listen to ports that ethernets are connected to? for example if i get two raspberry pi's and connect with ethernet. How can i query the ips connected to one of the pis?

#

I know once i have the ip i can use requests.get("") as client and flask as server

thorn stratus
#

Why can't you just grab the IP from the flask server

lusty ermine
#

because localhost is not available from another raspberry

#

and I can look it up with bash in raspbian but I am trying to learn in python so I can automate it and not have to look up the ip for all 5 raspberrys

thorn stratus
#

Well it's not something easy to automate

lusty ermine
#

yeah i think im going to run bash command from python

#

that may be ok solution for now

thorn stratus
#

You can scan your network, but that still wouldn't tell you what is what

lusty ermine
#

right.. I am thinking about purchasing a switch to connect em all

thorn stratus
#

Using static IPs would be the easiest solution

lusty ermine
#

yeah but the point is im too lazy to keep looking up ips and writing the ip manually

#

as i add more and more raspberries

thorn stratus
#

Yeah that's what static IPs could fix

lusty ermine
#

oh really?

thorn stratus
#

You know raspberry pi #5 is at 192.168.1.5 or something like that

#

#6 at 192.168.1.6

#

Lots of different ways to do IP schemes

lusty ermine
#

interesting... I wonder if it will add one as external ip after connecting to a switch

cobalt herald
lusty ermine
#

OMG ty!! thats exactly what I was looking for

#

@cobalt herald your a good one man im bookmarking this link

grave pilot
#

what are some networking projects

grave pilot
#

that i can do with python

gloomy root
#

make a mini http server

#

make a higher level http server on a existing low level one

#

interact with WSs etc...

grave pilot
#

WSs ? @gloomy root

gloomy root
#

Websockets

tidal matrix
#

TCP would be much better for something like a communication server right

gloomy root
#

TCP grantees that all the data sent will get to the recipient and in the same order they were sent

#

UDP for speed like Video streaming or Game streaming for example

#

TCP for messaging etc...

shy pebble
#

implement TCP style insurance on top of UDP

gloomy root
wide sail
#

On the subject of TCP: TCP can have some really bad performance over wireless links. This is because in wireless you can get these things called burst errors (heavy sporadic interference causing multiple packets to drop in rapid succession). TCP interprets this as heavy network congestion and decrease its sending speed to play nice with the network. I know there have been work to improve TCP to mitigate this unintended behaviour but many applications still use an UDP approach instead. What you do is use UDP with an application layer protocol on top which handles the stuff TCP usually do.

tidal matrix
#

Help

#

I got a simple server-client program working on one machine, now I transferred the client to another machine on the same network

#

I changed the HOST to my Server machines ipv4

#

However I get an "Winerror 10060 A connection attempt failed because the connected
party did not properly respond after a period of time, or established connectio
n failed because connected host has failed to respond"

thorn stratus
#

Did you already try it with firewalls turned off

tidal matrix
#

Did you already try it with firewalls turned off
@thorn stratus Yes

thorn stratus
#

private ipv4 or public

tidal matrix
#

private ipv4 or public
@thorn stratus private atm. Will switch to public after I get this working

wraith grove
#

can you ping the ip?

tidal matrix
#

can you ping the ip?
@wraith grove wdym

#

@thorn stratus UPDATE: I got Error 10061 No connection could be made because the target machine actively refused it

#

This problem is really weird

#

what could be refusing the connection

thorn stratus
#

A firewall usually

tidal matrix
#

Yep theyre all disabled

#

Anyone willing to try my code on their PC or is that not possible

tidal matrix
#

Has it got anything to do with port forwarding?

#

I have a port forwarding setup for a separate server

thorn stratus
#

If your on your own network with no NAT in the way then no

tidal matrix
#

Fair enough

vernal surge
#

@tidal matrix your IP isn't 127.0.0.1 is it? Lol

tidal matrix
#

Wdym

#

I tried that or localhost

#

But neither work

vernal surge
#

They won't

tidal matrix
#

They dont make a diff*

#

Thats on the server side

#

The client points to my server machine IP

vernal surge
#

What ip is your client pointing to

tidal matrix
#

192.168.0.89

vernal surge
#

Ok, what port are you bound to server side

tidal matrix
#

CLIENT:
HOST, PORT = "192.168.0.89", 9999
SERVER:
HOST, PORT = "localhost", 9999

#

Thats how I have it setup

vernal surge
#

Ok, you can't bind the server to local host

tidal matrix
#

Yea I left that as it was lmao

vernal surge
#

Have to either bind to '0.0.0.0' or to '', but quad zero is more explicit

#

On the server that is

tidal matrix
#

Ah ok

vernal surge
#

Then the client can point to your .89 address

tidal matrix
#

Hopefully its a stupid mistake like that ๐Ÿ˜‚

#

I'm just starting this whole networking thing aha

vernal surge
#

Localhost is reserved for intra-machine comms and will never be routable outside of itself

tidal matrix
#

Hoping to have a small server for a few people with a special strip system used in airports, for realistic simulations of airport ATC. A pilot would have the client and the ATC is the server. I am fine to do everything on either side just transferring the data is my problem

vernal surge
#

Actually, the whole 127/8 block is, but you don't see much else outside of 127.0.0.1

tidal matrix
#

Ahh ok

#

The name localhost suggests it

#

I thought its probably not listening outside the server but didn't know what to replace it with

#

And for this use case TCP would be my ideal choice

vernal surge
#

0.0.0.0 means "all outward facing interfaces"

tidal matrix
#

Ah ok

#

I have a small game server setup for this simulation etc etc but I just had to port forward that and was done ๐Ÿ˜‚

vernal surge
#

You could bind to the IP specifically, but if you are doing DHCP, that'll be a bug to hunt later in life

tidal matrix
#

Yes indeed

#

While we are at it, any tips for connecting the client to the server

#

Let me explain a bit more

#

The client has to connect to my public IP from another network correct?

vernal surge
#

Correct

tidal matrix
#

However my router changes public IP if it goes down

vernal surge
#

Or a DNS name, but that'll resolve to your pub

tidal matrix
#

Ah

#

So the issue is if it points to my public IP then it may change, or so I believe

vernal surge
#

It can, my ISP threatens that to, but I've never had my IP change lol

#

But it's good to plan for the case

#

So you need a dynamic DNS updater

tidal matrix
#

Ah ok. I have never seen it either, but they do say that if its down for a while or reset it'll use a different one

#

Ah ok

vernal surge
#

The cloudflare API is pretty easy as well though

#

And I think there are some DNS companies that have their own tools for that

#

But I don't know them

tidal matrix
#

Ah ok

vernal surge
#

The "API" for Google synthetic record updates is literally just a url (so it's easy to automate a thing that "updates" the record every 15 minutes)

#

Most of the time, I just set up a cronjob with a curl command

tidal matrix
#

Ahh nice

#

Fair enough

vernal surge
#

If you go the cloudflare route though, I have a thing I wrote in go to do that lol

tidal matrix
#

Wdym

vernal surge
#

It's a dynamic DNS updater for DNS hosted in cloudflare

#

Felt kind of advertise-y, so if you want the tool, I'll DM you

wraith grove
#

wait really? the whole 127.0.0.0/8 is reserved?

#

thats rly silly

tidal matrix
#

Felt kind of advertise-y, so if you want the tool, I'll DM you
@vernal surge haha that's fine, sure DM me ill check it out

gloomy root
#

How doesnt it work

#

other than your weird recursive start function

tidal matrix
#

What's the problem

#

It closes early?

#

I can help if its not to do with networking ๐Ÿ˜‚

gloomy root
#

thats because you double click it

#

you need to run it in IDLE or a ide

vernal surge
#

@ember ledge it's because you define server with caps, but do a bind with it lower ... The capitalization matters in python

vernal surge
#

@ember ledge also, your start function shouldn't need to call itself

vernal surge
#

Think through it a bit, give us your proposed fix, and we can help. I'm not one that is going to just do it for you โ˜บ๏ธ

tidal matrix
#

Thank you @vernal surge it works now!

vernal surge
#

@tidal matrix good deal

tidal matrix
#

Quick Q

#

If you are there

vernal surge
#

Always lol

tidal matrix
#

Will I be able to compile this basic server script into an exe with pyinstaller

vernal surge
#

That I don't know. I don't use python for compiled binaries

tidal matrix
#

Fair enough

#

Implementation would be better with something like C++ for what I'm doing but I ain't too good with that

vernal surge
#

I disagree, Go or Rust would be my choice for what you are doing

#

Probably go

shy pebble
#

pyinstaller should work fine I think

tidal matrix
#

Fair enough, but I am not familiar at all with them ๐Ÿ˜‚

#

pyinstaller should work fine I think
@shy pebble Was thinking so just confirming

vernal surge
#

Does pyinstaller literally just wrap python in a binary? Like, dependencies and all? I legitimately don't know anything about it.

#

And I question if (assuming you are not writing threaded it async code) the GIL still plays a factor in the end binary or if it is distributing the low level C code rather than the python

shy pebble
#

I think it pretty much just sticks the python interpreter, your code and a simple exe that handles unpacking and running it/

vernal surge
#

Ah, so no dependency handling

shy pebble
#

well, you just tell it what dependencies to include, but it does not download them at runtime as far as I know

vernal surge
#

Interesting, GIL question still stands lol

shy pebble
#

it is no different from just running python normally (except sometimes missing stdio), so the GIL is still there

vernal surge
#

Also, from what I remember from back in the day, getting EXEs were fairly simple, but what about "Linux/amd64|i386" or Darwin binaries?

shy pebble
#

it cannot cross compile, but I think it supports anything with a C compiler. But that would require testing

vernal surge
#

:+1:

#

I'll read more on it, I just didn't know the high level details :D

#

Feels like a decent enough stop-gap until you get around to learning a compiled language.

#

I'm all for the "use it until you can't" mentality :)

tidal matrix
#

Hey

#

In terms of keeping my server safe

#

What can I do

#

Because even if the people who have the client seem nice, I can never be sure

#

And the server will run on my standard residential network

vernal surge
#

@tidal matrix lol question of the last two decades lol

tidal matrix
#

Lmao

vernal surge
#

Look up the OWASP top 10, they have a lot of examples of how to secure the 10 most common, exploitable web things

#

And on server side, there is a lot you can do. Not least of all is keep your server up to date on patches, don't use EOL operating systems, and Google a general server hardening guide for your operating system

#

Networking wise, it's best to use a firewall that can do more than just port filtering, but in a residential context, it's unlikely you will have something like that.

#

(I use to run my own ISP, so I'm an outlier lol)

#

Also, don't just expose the python web server or use IIS. Generally speaking, use a proxy like Apache or Nginx to do the exposure, because they are a lot less susceptible to web based attacks (assuming you use the best practices and hardening guides)

#

Also, if you are using web sockets, then you are already subscribing to the RPC paradigm, so you really need to make sure your functions that clients can call don't do things you don't expect ... This is the hardest part ... So doing things like fuzzing and chaos testing helps alot.
Additionally, make sure you are throughly testing your code before deployment so you can catch unit and e2e level mistakes before a bad actor can.

#

</WallOfText>

#

I'm a firm subscriber to the zero trust model lol

#

And don't get me started on authentication lol

#

Anyway, hope that helps @tidal matrix

tidal matrix
#

Oh frick

#

Didnt see all that ๐Ÿ˜‚

#

Will read it now

vernal surge
#

This is why security is a career path in and of its own

#

And not to mention, the threat landscape changes hourly lol

tidal matrix
#

Certainly

#

Just now my Discord server had some incident

serene halo
#

Hey is anyone good in making packets with python raw sockets

wraith grove
#

!ask

errant bayBOT
#

Asking good questions will yield a much higher chance of a quick response:

โ€ข Don't ask to ask your question, just go ahead and tell us your problem.
โ€ข Don't ask if anyone is knowledgeable in some area, filtering serves no purpose.
โ€ข Try to solve the problem on your own first, we're not going to write code for you.
โ€ข Show us the code you've tried and any errors or unexpected results it's giving.
โ€ข Be patient while we're helping you.

You can find a much more detailed explanation on our website.

wraith grove
#

@serene halo

tidal matrix
vernal surge
#

@tidal matrix sure, I'm not at home right but, but I will when I get back

tidal matrix
#

Sure

vernal surge
#

@tidal matrix I assume you have a domain?

tidal matrix
#

@tidal matrix I assume you have a domain?
@vernal surge I do

vernal surge
#

Who did you register it with? Google?

tidal matrix
#

GoDaddy, UK website

#

Questionable name

vernal surge
#

Lol, GoDaddy is global my man

#

But GoDaddy doesn't have a solution they provide, but it would be easy to build a solution with their api

#

Otherwise, you would need to transfer the domain (which isn't free) to Google to use their synthetic records.

#

I'm glad to help you build something, or I could whip something up pretty fast for you.

tidal matrix
#

Ah ok

#

But what would using their domain do?

vernal surge
#

Who's?

thorn stratus
#

You mean using their DNS/name servers?

vernal surge
#

I've not had much luck with synthetic records just using NS records

tidal matrix
#

Who's?
@vernal surge Mine even

#

Hosting my domain on their server would make the target IP theres?

#

Makes sense

vernal surge
#

No, domains just allow you to point the name wherever

#

It can be in their data center, but can also be your house lol

thorn stratus
#

When a computer tries to find your domain it has to contact the DNS server that knows where it is

#

So all you are doing is changing which DNS server tells you where it is

#

The A record inside that DNS zone is what actually stores where your domain goes to

tidal matrix
#

Ah ok which would be my house

thorn stratus
#

Yep

vernal surge
#

And yeah, if you IP changes, you need a service to update your provider when it happens

tidal matrix
#

And how would I do that

vernal surge
#

With go daddy you to have to build something or use noip, but noip is convoluted

#

I'm sure you could find something prebuild on GitHub, but I don't know of anything offhand

#

I like to make those things myself though as a refresher for certain skills and languages lol

tidal matrix
#

Ah ok

vernal surge
#

I actually just wrote one for an iot project I'm working on lol

#

But it's for an STM32 board lol

thorn stratus
#

It's called ddns

#

There are a lot of things that do that for you

serene halo
#

@serene halo
@wraith grove Thanks

wraith grove
#

Are you not gonna ask your q?

vernal surge
#

Honestly not sure if helping with packet forging is against the rules or not though. Would depend on context.

tidal matrix
#

@vernal surge So say I got a new domain from google, and I setup a custom record that points to my server IP, could I make my client point to the domain, which would then indirectly connect it to my server?

#

Sorry I'm very new to networking aha

vernal surge
#

well, you don't need a new domain (unless you want one lol)

tidal matrix
#

Yea because my current domain is expensive and for a store I used to run which I dont anymore

vernal surge
#

but yeah, that is exactly how DNS works ... the thing in question was the dynamic-ness of your home IP

tidal matrix
#

Ah, would I manually be able to change it?

vernal surge
#

i think i remember you saying that it doesn't really change all that often ... so i might be trying to prematurely-optimize things lol

tidal matrix
#

By changing the destination DATA IP in the record

vernal surge
#

yes

tidal matrix
#

Yea never changed for ages

vernal surge
#

but yeah, you can manually change it

tidal matrix
#

However I will be switching ISP sometime in winter so

#

Ah ok

#

Cool thats exactly what I wanted to know

#

Thank you!

#

Also does the domain ending matter a huge amount or not

vernal surge
#

not really ... only for advertising purposes (like ... people tend to default to ".com" when they type things in the address bar), but so long as people know it's a ".xyz" or whatever, it really doesn't matter

#

the only ones that matter are the "secure" domains, like ".app" and ".dev" that require you to run a secure server

tidal matrix
#

Ah ok, wondered why those two are more expensive

#

But thank you for the help!

#

I will find a simple tutorial to use but should be straightforward

vernal surge
#

basically, you just add an "A" record with whatever alias you want (e.g. www) that points to your IP address

#

or if you use NOIP or something like that, you set up a CNAME record that points to the other URL

tidal matrix
#

yea I saw that

#

Which would be better

#

If that makes sense

vernal surge
#

A is easier, and probably best for your setup

tidal matrix
#

Ok cool

vernal surge
#

if you notice your IP changing, then address it then

tidal matrix
#

Also quick Q, how many clients could I practically connect to the server

#

Does it depend on bandwith

#

if you notice your IP changing, then address it then
@vernal surge Ok

vernal surge
#

yeah, a few things ... bandwidth / server resources

gloomy root
#

your server will probably clap out before the bandwidth

tidal matrix
#

lmao

gloomy root
#

concurrent connections wise

tidal matrix
#

Yea

#

Max clients in one go I would have is 20

vernal surge
#

realistically, on consumer hardware, on a consumer ISP, i would be surprised if you get more than 100

#

without benchmarking though, i have no real idea

tidal matrix
#

Yea max would be 20. The server machine is quite powerful too as it was my old PC

#

But ofc not as powerful as normal server machines

gloomy root
#

its your framework and code that makes the diffrence aswell

tidal matrix
#

Yes, the code here is simple af

gloomy root
#

How well your framework or server can actually use those reasources

tidal matrix
#

All the server is doing is receiving strings from clients. Thats it.

gloomy root
#

100 concurrent connections is regarded as 'low' for a framework or server thats being tested or put into th real world so you should be fine

vernal surge
#

simplicity isn't really the question lol, but how the code uses multiple threads or async ops (if at all)

tidal matrix
#

Yea aha it isnt that big

#

Fair enough

vernal surge
#

i can write really simple, really poorly performing code ๐Ÿ˜„

tidal matrix
#

It currently doesn't but I will make it so it does

gloomy root
#

honestly for 20 users i dont think youll have an issue

vernal surge
gloomy root
#

Like a sync based system using 1 thread can still chill with a few hundred connections a second and concurrency

tidal matrix
#

Aha yes. I programmed a mini auto-landing rocket (irl) the other day in C++ and even that relatively simple loop code could be massively optimised

#

Yea thats all that I would have. Thanks!

#

Oh one more thing, I saw a few people constantly closing the connection with the server after sending a string. This I assume has no benefit?

gloomy root
#

It has a massive server side benifit

tidal matrix
#

Really?

gloomy root
#

If the connection is kept alive the server has to keep using that thread or keep blocking other requests in order to keep it alive

tidal matrix
#

I thought it may reduce massive load when not being utilised

#

But thought thats quite a simple thing

gloomy root
#

if the server is able to drop that request after its done it free's stuff up to handle other requests

tidal matrix
#

Ah ok

#

So thats a good idea then?

gloomy root
#

generally, tho you'd want to check to see if the client hasnt disconnected alreadyu

tidal matrix
#

Ah ok

#

Well thanks for both your help!

tidal matrix
#

We got another problem!

#

Will using my public IP in the client only work if the client is currently connected to a different network to the server

wraith grove
#

Nope, should work either way

#

it will go out to your router, your router will say hey I know where to send that, from the port forwarding rule

#

then it will work like normal

vernal surge
#

Not entirely true @wraith grove ... some older routers (and even some new ones) needed rewrite rules to point to the internal address instead of the external (based on Origin filtering ... if it saw a packet come from itself, which is the case, it would filter it because "that isn't common")

#

but generally speaking, yeah, unless it doesn't work, assume it will ๐Ÿ˜„

tidal matrix
#

Hmm cause I tried it and I'm getting the same 'actively refused it' error when using public ip

#

Do i need a port forward rule setup for this?

vernal surge
#

yes

tidal matrix
#

But what forward to what

vernal surge
#

in your router, just set a rule that points <whatever you want the external port to be> to <whatever your service port is>

#

i don't remember the port, but i think i remember you doing 9999

tidal matrix
#

Yes I'm doing 9999

#

So thats my service port

vernal surge
#

yes

tidal matrix
#

My external port can be the same or no

vernal surge
#

yeah, it can be the same

tidal matrix
#

Ok but I must do the port forward for it to work

#

And then the client port is also 9999

vernal surge
#

yes, a port forward must exist if you want it to work outside your own network

#

don't worry about setting the client's outbound point, it'll get a dynamic one when it goes out

tidal matrix
#

Ok, so if I use a client in the same network that points to my public IP, will it be registered as an external signal coming in

vernal surge
#

depends on what your router does, but maybe

#

if it does any level of intelligent routing, you probably won't see an external client, but if not, then yeah, it'll go out and then right back in and it'll look like it came from your public IP

tidal matrix
#

Ah ok

#

Well ill setup the port forward now

tidal matrix
#

It works ๐Ÿฅณ

vernal surge
#

@tidal matrix hooray

paper dagger
#

have anyone experience doing web sockets with a RDS database like postgres or MySQL?

#

looking for a way to integrate the two via python

serene halo
#

Hello

cedar forum
#

@serene halo move your Q here and we'll have a look at it

serene halo
#

here is lib i am using

#
from genpack import *
from random import randint
test=TCP(randint(1, 65535),80).pack(b"192.168.0.243",b"192.168.1.1")
print(test)
#

her is my code

#

and its showing me error

#
Traceback (most recent call last):
  File "C:\Users\mayan\Desktop\testing.py", line 627, in <module>
    test=TCP(randint(1, 65535),80).pack(b"192.168.0.243",b"192.168.1.1")
  File "C:\Users\mayan\Desktop\genpack.py", line 154, in pack
    tcp_checksum = checksum(psh)
  File "C:\Users\mayan\Desktop\genpack.py", line 15, in checksum
    s+= ord(data[i]) + (ord(data[i+1]) << 8)
TypeError: ord() expected string of length 1, but int found
#

i guess its because i am using this in win and may be it only works in linux socket

cedar forum
#

so the checksum function is failing

#

it's not related to that

serene halo
#

yeps

#

ye

#

just just about creating packet

cedar forum
#

uhhhh

serene halo
#

it should work ๐Ÿค”

cedar forum
#

try passing things as strings

#

not bytes

#

because ```py

checksum(b"abcdef")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in checksum
TypeError: ord() expected string of length 1, but int found
checksum("abcdef")
53973

#

that checksum function is iterating over the bytes in that bytes object, but it doesn't give characters like the checksum wants (though it should be quite easily transferrable)

#

!eval ```py
print("> BYTES")
for a in b"abc":
print(a)

print("> STRING")
for a in "abc":
print(a)

errant bayBOT
#

@cedar forum :white_check_mark: Your eval job has completed with return code 0.

001 | > BYTES
002 | 97
003 | 98
004 | 99
005 | > STRING
006 | a
007 | b
008 | c
cedar forum
#

you see?

serene halo
#

that make sense leeme try

#

i see but i guess checksum should be in int, i am trying it first time

cedar forum
#

Yeah, checksum should be (and is using that function) an integer

serene halo
#

one person already using it leeme show you how he is using

cedar forum
#

!e ```py
def checksum(data):
s = 0
n = len(data) % 2
for i in range(0, len(data)-n, 2):
s+= ord(data[i]) + (ord(data[i+1]) << 8)
if n:
s+= ord(data[i+1])
while (s >> 16):
s = (s & 0xFFFF) + (s >> 16)
s = ~s & 0xffff
return s

print(checksum("Hello, DiceOfDeath!"))

errant bayBOT
#

@cedar forum :white_check_mark: Your eval job has completed with return code 0.

64580
serene halo
#

udp = UDP(randint(1

#

okay ๐Ÿ˜ฎ

#

wait

#

solved

#

๐Ÿ™‚

#

thanks

cedar forum
#

No problem, was it just the strings after all?

serene halo
#

yes string not bytes i was sending bytes data

cedar forum
#

Makes sense, glad you fixed it!

serene halo
#

!e

def checksum(data):
    s = 0
    n = len(data) % 2
    for i in range(0, len(data)-n, 2):
        s+= ord(data[i]) + (ord(data[i+1]) << 8)
    if n:
        s+= ord(data[i+1])
    while (s >> 16):
        s = (s & 0xFFFF) + (s >> 16)
    s = ~s & 0xffff
    return s

print(checksum(b"Hello, DiceOfDeath!"))
errant bayBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

serene halo
#

oops

#

Xd

cedar forum
#

I'll run it ๐Ÿ™‚

serene halo
#

thanks for your help

cedar forum
#

!e ```py
def checksum(data):
s = 0
n = len(data) % 2
for i in range(0, len(data)-n, 2):
s+= ord(data[i]) + (ord(data[i+1]) << 8)
if n:
s+= ord(data[i+1])
while (s >> 16):
s = (s & 0xFFFF) + (s >> 16)
s = ~s & 0xffff
return s

print(checksum(b"Hello, DiceOfDeath!"))

errant bayBOT
#

@cedar forum :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 13, in <module>
003 |   File "<string>", line 5, in checksum
004 | TypeError: ord() expected string of length 1, but int found
cedar forum
#

yep

#

No problem!

serene halo
#

thats the same error becayse if bytes data

cedar forum
#

yeah

serene halo
#

thanks again xD

cedar forum
#

No worries hah

serene halo
#

ah finally i find a better solution cause sending decode data in function creating problem

#

python3 already return int from but not python2

#

so is ```python
def checksum(data):
s = 0
n = len(data) % 2
for i in range(0, len(data)-n, 2):
s+= ord(data[i]) + (ord(data[i+1]) << 8)
if n:
s+= ord(data[i+1])
while (s >> 16):
s = (s & 0xFFFF) + (s >> 16)
s = ~s & 0xffff
return s

print(checksum(b"Hello, DiceOfDeath!"))

#

error is because we are passing int variable to ord

#

solution just remove ord

#
def checksum(data):
    s = 0
    n = len(data) % 2
    for i in range(0, len(data)-n, 2):
        s+= data[i] + (data[i+1]) << 8
    if n:
        s+= data[i+1]
    while (s >> 16):
        s = (s & 0xFFFF) + (s >> 16)
    s = ~s & 0xffff
    return s
bitter kite
#

How do you shutdown an aiohttp web.Application?
await app.shutdown() doesn't work and throws RuntimeError: Cannot send non-frozen signal.
Please ping me if you have an answer, thanks!

solid iris
#

hello guys

#

it might be a simple question. sorry im new to python and everything

#

is there a way for paramiko to save show run hostname name as my text file name?

vernal surge
#

@solid iris I guess that means you are saving all output to a txt file?

solid iris
#

yes

vernal surge
#

can i ask why? lol

copper robin
#

@keen pawn how is that related to the channel?

tidal matrix
#

Was looking at cloudflare etc

#

Cloudflare seems really nice and advanced, but not needed for me

#

The ddos protection is also good

tidal matrix
#

@vernal surge Are you awake ๐Ÿ˜‚

#

Sorry for the ping

vernal surge
#

@tidal matrix always lol

tidal matrix
#

Great, a little help setting up the google dns?

#

This tutorial is eh

vernal surge
#

Setting it up to do what exactly

tidal matrix
#

Just point to my server with ipv4

#

So the client > domain > my ipv4

vernal surge
#

Right, do you have a domain there?

tidal matrix
#

Yep

vernal surge
#

Ok, then you just go to the DNS section and add an a record

#

Unless you want to do a synthetic record

tidal matrix
#

I understand everything on that page apart from the CNAME and A things

vernal surge
#

A points right to an ip address

tidal matrix
#

A synthetic record seems easy but I would like to the custom record

vernal surge
#

Cname points to another domain name

tidal matrix
#

Ah

vernal surge
#

Normally, you don't need to worry about ttl

tidal matrix
#

And what is ttl

#

Oh ok

#

Just leave it blank then

vernal surge
#

Unless it complains (in which case, set to 300 seconds)

tidal matrix
#

Ok so the first box is just Name

#

a bit confusing

vernal surge
#

Yea

tidal matrix
#

with an ' inside

#

@*

vernal surge
#

@ is the "self"

tidal matrix
#

which is

vernal surge
#

If your domain is "jray.dev" then the @ record responds to any protocol not pointing at a specific record (e.g. http://jray.dev)

#

Otherwise, you need a resource record

#

I tend to tell folks starting with DNS not to worry about that and just name it

#

Such as WWW

tidal matrix
#

Ah ok cool

vernal surge
#

Technically, you could have www and @ point different places, but that's not really done lol

tidal matrix
#

Ah wow

#

Wouldnt see much benefit tbh

wraith grove
#

you might want to worry about ttl

#

high ttl = less queries but any changes will take longer to propagate, low ttl means the opposite

#

And the name of the record is the subdomain of the zone it is

tidal matrix
#

Ah ok makes sense

#

Also is it worth using the free cloudfare ddos protection?

#

Just requires changing the nameservers

vernal surge
#

Cloudflare free ddos is not super useful in a real ddos scenario, but it's better than nothing

#

@wraith grove and not that I mean it's not important, but for what he is doing, it's not lol

tidal matrix
#

Cloudflare free ddos is not super useful in a real ddos scenario, but it's better than nothing
@vernal surge Yea just adds another small protection.

#

And even their low paid version is much better than something like AWS Shield which I was looking at

#

Of course I would do many network upgrades before upgrading to a substantial ddos protection and when I expand to take upto 100 clients in one go.

#

But the risk even for 100 clients is very little

#

Hmm my WiFi has just crashed and isn't reconnecting

#

Wonder if its related ๐Ÿค”

#

I dont think that's technically possible though

rigid edge
#

can any one explain some python basic socket stuff -- can you PM me

wraith grove
#

Why not go through any tutorial or the docs, try to make something, and ask questions here when there is something you don't understand

faint hemlock
#

Someone's looking for help with paramiko in #help-peanut if anyone has time to take a look.

limber plume
#

Maybe someone with more sFTP knowledge than myself can help. If I'm on the same LAN as my sFTP server, is there any benefit to connecting with the public ip vs the local ip?

#

Speed wise it appears to be the same. The only difference I've noticed is that if my internet connection drops, then I can't connect to my sFTP server if I used the public ip. Am I missing something else?

wraith grove
#

if you aren't using it from outside the local network, you should just not port forward and use it from the private ip

#

otherwise I don't think it makes much of a difference, but usually you would use the private ip

#

if it makes things more convenient with like dns and stuff though the public ip is fine

limber plume
#

Got it, thanks a bunch. It was just about dns convenience ๐Ÿ‘

tidal matrix
#

What will I have to change in my original code to get this new domain working? My client currently points to my public IPV4 and everything works fine. Do I only need to change the IPV4 to my domain in the client, or is there more I need to change?

#

@ember ledge Be patient, you posted your question 2 mins ago. Noone here is obliged to help you, they are doing it out of their own kindness

#

It will take some time for a response

#

@ember ledge its because you didnt define 'server'

#

Instead you put capitals 'SERVER'

#

Change everywhere it says SERVER to server

#

Then tell if its works

#

Yes put all to small

errant bayBOT
#

You are not allowed to use that command here. Please use the #bot-commands channel instead.

tidal matrix
#

thx for the help i relly like it
@ember ledge No problem

#

What will I have to change in my original code to get this new domain working? My client currently points to my public IPV4 and everything works fine. Do I only need to change the IPV4 to my domain in the client, or is there more I need to change?

candid lion
#

Hi

#

Im new here

tidal matrix
#

Im new here
@candid lion Hi new here, Im @tidal matrix

candid lion
#

Hi ๐Ÿ™‚

#

Can you please tell me about networking

#

Im interested

#

@tidal matrix ?

tidal matrix
#

Emm I just started too ๐Ÿ˜‚

candid lion
#

ok

tidal matrix
#

If it's anything extremely simple then yes but I'm not one to teach aha

vernal surge
#

@tidal matrix yes, all you have to do is change your client to point to the domain name

#

Shouldn't have to change your server at all

#

@candid lion that is a very loaded question lol. What do you want to know?

serene halo
#

Haha ๐Ÿ˜„

vernal surge
#

Also, I assume you mean computer networking, but there are other types of networking (social networking, telecommunication networking, lol)

serene halo
#

Lol true thing

vernal surge
#

I did telecom before computers, so I have the battle scars

#

And I still own a butset and a punch down tool just in case lol

tidal matrix
#

@tidal matrix yes, all you have to do is change your client to point to the domain name
@vernal surge cool, I setup the cloudflare dns so it'll take upto 48 hours to change

serene halo
#

So you have good knowledge in network signals like radio

vernal surge
#

@serene halo yeah, I do some HAM radio stuff too (I'm also a weather nerd lol)

serene halo
#

Wow

vernal surge
#

@tidal matrix that is usually worst case, most folks that use primary DNS providers will see the change in less than an hour

serene halo
#

My friend is also good in radio signal and idk how he got police radio signals lol

tidal matrix
#

METEOROLOGY WOOO

#

@tidal matrix that is usually worst case, most folks that use primary DNS providers will see the change in less than an hour
@vernal surge ah ok

vernal surge
#

@serene halo police two way is easy to intercept. But most departments have scramblers (encryption) now, so they are usually in those channels

serene halo
#

Yeah

#

Are you also good in computer networking ?

tidal matrix
#

Aircraft comms is fun to listen to

vernal surge
#

Some would say that, I have my CCIE after all

#

Although, it's in security, not route switch, but I have a CCNP/RS so I'm ok I guess

#

I ran my own ISP as well

#

Until I got bought out

serene halo
#

Are you ccnp?

#

Damn thats cool haha

#

U are a internet service provider

#

Nice

#

Where ?

vernal surge
#

I'm not anymore, a bigger company bought mine, so I don't do it anymore

serene halo
#

Ah alrighty

#

So bro have you ever tried to generate packet ?

#

Like in python creating raw socket

#

And sending struct packet

vernal surge
#

I don't do that in python usually, but yes, I've done it

serene halo
#

Das cool i got stuck in it

#

I am trying to create packet and its unfortunately not working

#

I don't do that in python usually, but yes, I've done it
@vernal surge in which langauge ?

vernal surge
#

Ruby if I want to share it (because metasploit) or Go/Rust if I'm doing it for real

serene halo
#

Can you help me a lil and tell me whats my mistake if i will show you my code

#

Cause i am truly depressed now lol

vernal surge
#

Depends what you are trying to accomplish, I'm not going to help you hack anything lol

serene halo
#

Na dude

#

I am not h4xing anything haha

tidal matrix
#

Sounds legit

#

๐Ÿ˜‚

serene halo
#

I iz gud boi

#

๐Ÿฅบ ๐Ÿ˜›

vernal surge
#

Honestly, what you are trying to accomplish I'm sure had already been done in metasploit

#

I would check that out

#

Or run Kali and go to town

serene halo
#

How can you tell lol

#

You probably saw my screen shots posted above

vernal surge
#

No one does raw packet manipulation unless you have a purpose

serene halo
#

๐Ÿ˜„

#

Just wanted to learn

#

Think if i only wanna spoof packets i can use other scripts and tools

#

But thats not the things

vernal surge
#

Yeah, I don't mind helping people learn security, and there are lots of places to do so online (https://cybrary.com) but I'm not going to hand-feed a script kiddie without you knowing that you can easily go to jail, even for a simple mistake.

#

Not exactly something I'm going to get involved with in such an informal situation

serene halo
#

Thats true

#

You can atleast tell me the learning source

#

Cybrary is good i have used it

#

I even have their certificate fir tcp/ip with 80%+

#

But its been year i guess

vernal surge
#

Cybrary has a lot of courses

serene halo
#

And does they use python cause python is my main language

vernal surge
#

If you really want to learn security, check out the Offensive security courses

serene halo
#

And there they teach stuff like this rite ?

vernal surge
#

Yeah

serene halo
#

Yeah sure thanks bro i Better learn everything myself

#

Thats gives good experience

vernal surge
#

Yeah, that way, when you do to jail, you can't say I taught you the technique ๐Ÿ˜‚

serene halo
#

Haha super secret ๐Ÿ˜‹

#

Bro how many langauge you know

vernal surge
#

They are just tools, but idk, I use 4 regularly, but I can write in 8/9

serene halo
#

Which one ๐Ÿฅบ

vernal surge
#

My main Languages are Go/Rust/Python/C ... But I can write in Ruby/C++/Java/C#/Haskell/Scala and less so a few others

serene halo
#

Damn bro

vernal surge
#

Like I said, they are just tools

serene halo
#

I know python js bash shell and some c++

#

Ye

vernal surge
#

Ah, I forgot js and dart lol

serene halo
#

Bro you looking a way older than i thought i am just 20 rn

#

Lol

vernal surge
#

32

serene halo
#

And from when you started learning these things

vernal surge
#

16

#

Well, 12 for C

serene halo
#

I am late

#

I dont wanna waste my life

vernal surge
#

Never too late to start

serene halo
#

Thanks ๐Ÿฅบ

#

May i add you bro

vernal surge
#

Cybersec in the US is at or near a 0% unemployment rate, so it's a great career to be in lol

serene halo
#

Wow

#

Thats really a good stats

#

I guess i been doing this from 16

#

I first started with pen test

#

Then i dive into hacking and stuff

#

With programming

#

๐Ÿ˜„

vernal surge
#

Yeah, you can't do pentesting well unless you know how to do some Programming

serene halo
#

True

vernal surge
#

If you can't simulate an APTs TTPs, then you are doing your customers a disservice and giving them a false sense of security

serene halo
#

Hmmm bro

#

Bro someone told me today i cant gen packets with python

candid lion
#

@candid lion that is a very loaded question lol. What do you want to know?
@vernal surge How to do networking in wireless network?

serene halo
#

Move to c or c++

#

Change to monitor mode

#

And learn aircrack ng and all thei family tools

#

If you are talking about wifi networks

vernal surge
#

You can use python, python is really just C

#

You just need a library

#

There isn't a lot of low level stuff in the stdlib

serene halo
#

Hmmm

#

I am learning more in js these days like advance then i will so some js ctfs