#networks
1 messages Β· Page 43 of 1
if you have enough clients it will take quite a bit of time to send the data to every peer
in that case you might want to check if you are over a specific threshold number of currently connected clients and if you are you could fire off a thread that takes the data and addr as input and sends that data to every client except the client it came from
long term you could even have worker threads in a pool ready to work off a queue, where a worker would take one of the messages and send it to all clients and the next thread in the pool would do the same with the next message in the queue
but i think you can start of and make it work without threads to start with, it will probably be able to handle enough clients to start with, then you can add threading and thread pools and such later on
@wise jungle it's generally not good to start optimizing long before it's even a concern
premature optimization makes development of the software takes much longer and many times totally unnecessarily (a lot of the time it can even kill projects before they are done)
as long as your general design is correct i would suggest optimizing the code when you need it or when you got the core functionality working and not before then
when then is done you can probably do some refactoring of the code and then you can use performance measurements of your code to pinpoint what part of the code needs urgent attention to remove performance bottlenecks
im not trying to optimize the code im trying to fix it and make it do what i want
if you try to use the app
you will notice a fat latency
when u use more than 2 main.py
sometimes it even bugs out
and you cant hear anyone
and its just choppy and messy
i understand, but having threading in there right now is probably one of the sources of your problems
the most recent code i sent was just to test
but im essentially using what i put up on the repository
it's the code in the repo i'm looking at
yea
when you use
serverObj.udp_server.sendto(d, c)
does that block it till its sent or
@cloud spruce
on a blocking socket it could, but i think it will only do that if the kernel transmit buffer for the socket is full already, in all other cases i think it should be quick
AttributeError: module 'socket' has no attribute 'SOCK_NONBLOCK'
@cloud spruce
that's strange, it works on my linux, but you can use your original line instead and then add another line with udp_server.setblocking(False), the end result should be the same
I get the other error as shown earlier
.
hmmm, sounds like it's not supported under windows for udp then π
or wait, i think i know what it is π
our code is probably just too different, i'm doing something along the lines of (simplified and adopted to your constraints):
import socket
from select import select
udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_server.setblocking(False)
udp_server.bind(('', 5555))
sockets = [udp_server]
while True:
ready, _, _ = select(sockets, [], [])
for sock in ready:
data, peer_addr = sock.recvfrom(4096)
```where the `select()` will be blocking, waiting for any data to arrive on any socket that we are monitoring (right now only one)
The windows IOCP api is light years better than select.
You have no excuse for not using it, aside from the fact the only built-in library that exposes it, is asyncio.
(As the proactor loop)
select is pretty much an artifact of the past at this point.
how to join a vpn with python + create a local website on that vpn
so when anyone join that vpn will enther local website's ip
What?π€¨
yea
sounds like you are talking about a captive portal, but for users of a vpn when they first connect to the vpn and try to access anything after that
do you want to try to explain again what you want to do?
so, just be able to access an internal website inside a lan using a vpn from the general internet?
i'm not sure if i understand you right
but if it's like hamachi, every user that should participate connects to the vpn and they can reach each others computers and other computers connected to the vpn, right?
yes
so, the computer you want to access the website on that has the webcam streaming would also connect to the same vpn as you would be connected to
this is more or less a standard feature a vpn, you just have to make sure clients has the right to access each other through the vpn gateway, client isolation features must be turned off
then there might be a problem if the computer you are trying to access is running a host firewall that would stop this traffic from getting through
idk python so can u say a github page this have?
your question doesn't have much to do with python, it's self hosted VPNs in general and configuration of such a VPN
the other part is the web page that you want to display, that can be everything from a basic web server just hosting static pages to a complex web app that can be written in for example python using one of its many excellent frameworks
any examples of dat
this is what i tried to do and didnt work either
i thought it might be my network thats ass
and hosted it on google cloud and got the same problem
you really need to rearchitecture your code, right now in your server code it looks like you will be spawning one thread per datagram that you receive on the socket
yeah, the repository you posted
i'll take another look at that part and read it more careful then, i kind of skipped over parts of the threading since I think that should just be removed for now
the crazy threading shit was just yesterday
self.acceptConnectionT = threading.Thread(target=self.acceptConnection)
self.acceptConnectionT.daemon = True
self.acceptConnectionT.start()
the only thread created
so that the server is able to do commands/send messages
what are you planing to do with the import of wave, mix together several peoples audio streams on the server side?
aha π
the main things needed are these
import socket
import threading
import time
import traceback
for server.py
but i was just testing listening to incoming data
snyone that knows how to create a software that allows to trace ip's from friends to troll ?
how do you mean with trace?
would you have the ip address of the person you want to "trace" or is that what you want to find out
or is it information like isp, location or even person (which you generally won't be able to) that you want to find?
nah i mean i want to know his ip
do i have to port forward if i want to make a server which is accessible from the wider internet
yes
like say if i wanted a multiplayer game in python which me and my friends could access not just on my LAN
k
can you port forward using python
no, its a router setting
it all depends on the environment, is it on discord or what are we talking about here?
if you can get them to run a python script then its possible however this kinda thing sounds sketchy lol
yeeah thats kinda like a token grabber
ik but my friends are stupid and dont know how to portforward but still would want to host a server so im trying to automate the procces
i know a python script for that if u want but
its a little sketchy
only one person needs to host the server, the rest of your friends can then connect to that without port forwarding if that helps
ik
what would you do with their ips??
@mystic onyx
@coarse heath either your friends port forward when they want to host a server or you host the server permanently on a raspberry pi or something for them to connect to or find a service to host it for you lol (aws or something)
educational purposes only
what would you be learning π
ethical hacking
making your friends aware of the risks
yup
sock.connect((socket.gethostname(), 1234))
while True:
msg = sock.recv(1024)
print(msg.decode("utf-8"))
if socket.close:
break
```Is this valid?
sure, it will work just fine
you just have to add the import socket line above that, but i guess you just left out the imports from the code you posted here
import time
#AF_INET - IPv4, SOCK_STREAM - TCP
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1234))
s.listen(5)
while True:
clientsocket, address = s.accept()
print(f"Connection from {address} has been established!")
clientsocket.send(bytes("hi!!", "utf-8"))
if s.close:
print("Connection closed")
break
```
Server.py. ```
import socket
import matplotlib.pyplot as plt
import numpy as np
import time
#create a socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((socket.gethostname(), 1234))
while True:
msg = s.recv(1024)
print(msg.decode("utf-8"))
client.py. Can someone run this code and tell me why that error is happening. I would explain it, but I can't. The terminal just bugs.
nvm I was looking at the wrong terminal
but
when I run both files
and I look at the client.py file it says connection closed? how come?
help pls β€οΈ
if s.close:
print("Connection closed")
break
Take a moment to let this sink in.
Doesn't anything seem ... off?
uhh...
I don't see it... π
First off, what is s.close?
No idea I asked this above:
^
he said it works
^
Yes I guess so.
But if it performs the operation of closing the socket, why are you treating it like a state indicator, a true or false value?
I'm not?
Okay wait I'm confused, my thought process was like: if the socket closes then it will say connection closed
I am sorry for the bad questions. I just want to get directed to the right path and I will start research
"If the socket is closed, do something".
But who or what closes it?
This isn't a straightforward issue, there are many tangled problems here.
First off,
socket.close is a method that closes the connection instance when called.
socket.close is just the method object. You are not calling it therefore it is not closing the connection.
In addition, even when called, it does not return true or false, indicating the connectivity state of the socket.
Therefore you can't use it in an if statement.
However since you do anyway, python implicity tries to convert the method object into a boolean value.
Every empty/null or zero value in python is falsy.
Therefore socket.close is truthy, but that doesn't communicate any real information.
Since the if executes anyway despite nothing being correct, the break executes, and by extension the program ends since there's nothing else to do.
When the server process is done, of course the client loses its connection to it.
Okay, thank you so much.
But you see what im trying to do right? Any idea how I can do it?
Maybe, there's another issue, that is the socket whose close method you're referencing.
You want to check if the server is closed?
What are you trying to do?
When I close my client socket I want the print("Connection closed") to show
When the server or client is closed? Are you sure you're not mixing up the two?
I want to verify that's really what you want.
client* mb
im still clueless @cloud spruce
Most likely a code 10054 WSAECONNRESET will be raised, if you're on windows.
https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
But eitherway in python that'll be the ConnectionResetError exception.
You have to wrap all IO performed on the socket in a try/except to catch that exception.
When catched, meaning that client has disconnected, handle it accordingly.
quick update still lagigng like crazy (when more than 2 clients start sending data)
https://github.com/e1pupper/VoiceChat
You aren't using multithreading or asyncio, so the clients communicate sequentially
e.g. you have to wait for one client to finish sending or receiving data before moving onto the next one
How do i solve that issue
Do i just make multiple threads for each client thats connected
I'd need to see your code for that to give you any advice
it also looks like you are recieving from the server socket??
some weird stuff is going on in your code
oh this is UDP, not as familiar with that
multicast might do the trick?
for sending the data back at least
and then you could have the sending run in a seperate thread than the recieving
unfortunately multicast doesn't work out on the broader internet
most ISPs will not support it other then within their own networks, and even then it is often restricted to their own services like IP TV and such
hey guys. does anyone know how to import QEEG data? where should i start in programming to learn this?
in what form do you have your qEEG data and what do you want to do with it?
and i'm not sure this is the channel for that unless you fetch the data over the network as we are in #networks right now
it's in the form of mat files
something like this https://mne.tools/stable/index.html ?
oh i didn't realize that. i only asked here cause i heard python would be the text editor to use for this.
Channels.mat :like this
is this matlab files?
omg this is super cool thanks!
i think so. i'm not even sure! i'm so clueless dear god
considering how truly clueless i am , if anyone could recommend any books or websites i'd appreciate it!πΈ
if you just want to crunch numbers like https://towardsdatascience.com/how-to-load-matlab-mat-files-in-python-1f200e1287b5?gi=7ed4c6b55244 then #data-science-and-ml might be a more appropriate channel for that (i hope i'm not referring you to the wrong channel now)
it does help if you elaborate what kind of data your working with and what you want to do with it (the end goal, not any intermediate step, to not fall in the "xy problem" trap)
should i ask the same question there?
maybe a slightly refined version of that question in that case, where you say what kind of result you are looking for or in what way you want to process the data
ok thank you so much i'll try
a lot of the times when working with data sets you will be using the python libraries "numpy" and/or "pandas"
and depending on your task "jupyter notebook" may be applicable to you: https://jupyter.org/
so i should learn to use this one? thankyou πΈ π«
it depends on what you want to do, i don't have enough information on what you're doing with the data to give you a better answer
@lost dagger: sorry for botching that, @earnest blaze was totally right, i was not paying enough attention to your code π§
hey guys, I've just started using twisted as the base for a local proxy I'm running. Works great so far. Until now, I've been able to specify my proxy address and port in the client to connect to (e.g. 0.0.0.0:1234) instead of the real server. Proxy listens on this address and forwards to upstream server. Now, my scenario is that I can't tell the client what ip/port to connect to, it chooses itself. I know the ip/port it tries to connect to. If I do netsh interface portproxy add v4tov4 listenaddress=<server_addr> listenport=<server_port> connectaddress=<proxy_addr> connectport=<proxy_port> , I think this wouldn't work cause it would apply to both the client and the proxy itself, so the proxy would redirect to itself?
sounds like you need to intercept and redirect the connections either on the client computer, the server or somewhere on the network in-between where you have control to do so
what kind of protocol and client application are we talking about here?
it's a tcp chat client. I want to run this proxy on the same box as the client
Only concrete things I could have is knowing the process id that tries to connect, and the ip/port in advance
so instead of 123.249.142.6:3600 I want it to connect to my proxy that's listening on 0.0.0.0:1234 which is running on the same machine
but I don't have control of the client (well to rewrite it I mean)
if it's encrypted communication you will have a hard time doing anything with it anyways
it's not encrypted, I've seen the traffic over wireshark
but that's another question also
If you can intercept the handshake for the encryption, you can get the key material to decrypt the following packets no?
so, you want to be able to modify the traffic in some way as opposed to just see it like with wireshark?
if the encryption is not plain rubish you will not be able to decrypt it with only the data in the handshake
they would use asymmetric encryption and/or something like diffie-hellman for the handshake or on rare occasions pre-shared keys
ah okay, so the traffic that is sent to the server is encrypted with the server's public key? But the downstream traffic, the client needs to have information on decrypting that right? So I could decrypt 1 way?
not that this applies here, just curious to know
I guess I would need the private key of the client, and the client doesn't send that over the network either
no, for TLS/SSL they exchange one key for traffic client->server and another for server->client that is used with symmetric encryption, asymmetric encryption is only used for the exchange of the keys
diffie hellman my beloved
the client will only have a long term private key if it is using client certificates (like with mTLS)
otherwise it's just a temporary session keys used for the symmetric bulk encryption
so the symmetric key then must be resident in the memory of the client
"my precious" π
yeah, the symmetric components are stored in RAM
yes, it will be for the duration of the session or until it's rotated to a new one for long sessions
well written applications will try to make it hard to find and extract the key from memory, so your mileage will vary
I wonder if TLS 0-RTT affects that though, I've been meaning to talk to my prof about how 0-RTT actually works
0-RTT isn't great though, risk of replay attacks
ahh yeah operates off stored PSKs, that makes sense
TLS is pretty great stuff, lots of exciting developments in coming years
new quantum-safe algos will be fun (and maybe terrifying for performance, lol), encrypted ClientHello is also exciting stuff which should manifest in the near future
yes replay attacks is a concern for 0-RTT
it's already all here in TLS 1.3
yea they're all extensions to 1.3, but no wide rollout of any of them yet
ECH is in firefox now though, and Cloudflare is starting rollout iirc
TLS Encrypted Client Hello (Internet-Draft, 2021)
still waiting for DTLS 1.3 to be finalized...
DTLS π€
oh TLS for UDP?
well, for any datagram protocol
that's pretty cool, I've never seen that before, makes sense that it exists though
to defend against replay attacks when using 0-RTT i'll imagine we will need to take measures looking a bit like those used to defend against csrf and where the tokens would be one time use only
exactly! π
yeah -- the appendix to 0-RTT says that you need to handle it at the application level -- which frankly I'm not sure is great
Cloudflare were very big on the rollout and don't really mark anywhere the risks -- I'm unsure if they have mitigated them
sounds like a disaster waiting to happen for customers that are unaware
financial transactions anyone?
sure, and the same one again and again and again... π
hahahahaha exactly
ahh seems they have mitigations in place -- that's nice at least
well, their mitigation seems fairly sane, they only allow 0-RTT on GET requests with no query parameters
which providing people follow idempotency of GET should be fine
nginx does a similar thing to retry idempotent requests
and they attach a header when their edge connects to origin which uniquely identifies the RTT PSK
so their deployment is fairly sane, but I do fear that people off Cloudflare are going to do silly things with 0-RTT
yo what was the thing the other guy said when he said select is outdated
he said something else that i forgot
IOCP
that will limit the usefulness of 0-RTT severely for complex apps, but still great for CDN:s and such
ty
yea that's true
select() may be "outdated" on windows, but not on unix/linux platforms where it is more versatile and performant
also rnd ive tried select but no luck with that
i ran the server script on a unix machine
still got the same problem not sure
slowly losing hope
not sure what to do next
it's because of how you're implementing it (not meant to be offensive)
im not sure how the way im doing it is bad to be honest
i feel like its just as simple as it is
it's not, it's easy to go wrong with these things
after all the main thing i want to do is just forward the data to all the people "connected"
are you sure the problem isn't in the client code?
it too needs to be either running the reading from the socket in it's own thread or be non-blocking (or have very short timeouts)
its reading from the socket on its own thread (client side)
and from the audio device and then sending it through the socket in another?
no the sending data part isnt threaded i think
it doesn't need to be as long as it's a different thread from the reading operation, as the main thread is more or less just another thread
I'm aware, but we also know nothing of his usecase
Just a simple voicechat i sent the github link multiple times
Its on a different thread
with "usecase" i think @thorn stratus was referring to the environment it will run in, like lan or wan
i just assumed it was a requirement to be able to run over the general internet as well
in that case multicast is out
I think the main thing you need to do is send the data out on a seperate thread than you recieve it on
Both lan or wan
I tried that
I created a thread class that sends data to all the clients
Still choppy and slow
When two people are using it its absolutely perfect
No problems no latency
can you show the code?
.
Github link
Its short nothing crazy
that doesn't have any code that sends on a seperate thread than you recieve on
at least for the server
Let me scroll a bit and find it i sent it here before
whys that?
.
because if you do it on the same thread you have to wait for the data to be sent to each client before you can recieve any more
Yup i tried that
Still same issue
I think recieving the data is the bottleneck
As its a constant stream
you will probably end up with almost the same problem when trying to re-transmit the data you received anyways, just queuing at a later stage
Modern connections should all be full duplex, I don't see how you would have the same problem
Idk if you would want to try it you should
You can try and run 2 main scripts and see how it doesnβt lag
Then when u add a third its starts going crazy
only if you've hit the sockets send buffer size right? i see what you mean tho
as this is udp and all the connections are using the same socket and you need to send all data you get from each client to all the other clients you can sill build up a queue for outgoing traffic and huge buffers in the application if you can't send the data fast enough
It still takes time to write the data to the buffer
True, but I doubt he is hitting a bandwidth limitation with 3 clients
I thought i was but i hosted the server script on google cloud and had the same issue
but not much with non-blocking sockets
So in the code you linked you aren't sending in a seperate thread than you are receiving in
Ya i guess but even when i updated it to what i sent earlier had the same issue
I'm referring to what you sent earlier
I sent a github link and updated code
the code in your github repo is four days old
Thats not what i meant
The github link is the og code
I then sent the updated code in discord
Look at these replies
in that code, you send and recieve in the same thread, and there is some missing code as well
True, but you are still gonna be blocking when you call select
I haven't really worked with non-blocking sockets at all though, I'm not sure if they would help here or not
no, select() doesn't block unless you give it a timeout value as well which if given will only "block" until the timeout if there isn't any activity on any of the sockets select() is monitoring for reading within that time
you mean if you give it a timeout of 0 it won't block?
The optional timeout argument specifies a time-out as a floating point number in seconds. When the timeout argument is omitted the function blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.
or if you don't give it a timeout at all
in that case it will block
not if you only select on non-blocking sockets, at least on linux
but you'll burn cpu cycles that way, so you probably want to block or have a low timeout value if there isn't any activity on any of the sockets anyways
no, sorry, your (and the docs) are right, it blocks without a value even on only non-blocking sockets, i was using a 0 timeout in my code when i tested
im back
class serverHandler(threading.Thread):
def __init__(self, mainServer, data, addr):
threading.Thread.__init__(self)
for c in mainServer.connections:
if addr != c:
mainServer.upd_server.sendto(data, c)
but it doesn't matter much if it's blocking on select() if all actions that is initiated when there is any data available
otherwise you can have a timeout to be able to take other actions at intervals even in the absents of incoming data, low enough but not so low to run at 100% cpu
@thorn stratus
that doesn't run the code in another thread
when you create the object it sends all the data, not when you start the thread
you need to implement the run() method
in the main thread i do
d, a = self.udp_server.recvfrom(2126)
self.clients[a] = time.time()
#stuff here
serverHandler(self, d, a)
yeah that does not run it in a separate thread
yes it does
no, it just creates a new thread object, which runs the code as part of the object creation, and then throws it away
to run it in another thread you need to put the code you want in the other thread in the run() method of the object and then call .start() on the thread object
it
really
i swear when you do
class name(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
starts a thread
for that class
and its seperated
breh
no fucking way
ima test
i mean even tho it does dat i still got da same problem
cause i also do tried this
self.sendDataT = threading.Thread(target=self.sendData, args=(d,a), daemon=True)
self.sendDataT.start()
except Exception as ex:
print(traceback.format_exc())
def sendData(self, d, a):
for c in self.connections:
if a != c:
self.udp_server.sendto(d, c)
you could use something like asyncio if you wanna get around that limitation
or yeah use another socket object
you don't think @wise jungle can get away with that when it's a udp socket?
the python docs specifically say the socket object isn't thread safe. I can't speak to it's implemenation so I'm not 100% sure though
alright
lets say we got 2 socket objects then
one to send and one to recieve
on the send socket
you can just send to address that the other socket has recieved from
correct ?
do i need top have 2 ports for each server if thats not the case
one for receiving data and one for sending
you'll have to send back to the source port it came from also but yeah I believe that should work
can you really have to different socket objects for the same socket/port like @wise jungle needs?
i don't think you can
no, how would you pass the data between them?
as you want to receive data from any client and send it back to all other clients that is connected to the server port
on each one
create the receiving server object first
then create a sending server object later that is referenced to the server
oh, okay, you could but then you need one unique port for each client, it doesn't scale well
I think asyncio is really the answer here
tcp would also greatly simplify this
although there is quite a bit more overhead
Having some type of buffer on the client would also help resolve stuttering issues, rather than it being 100% real time
it would but its a voice chat
voice chat can be done over tcp
if u use tcp it would be very laggy and choppy
its better to use udp
that's not true
really quick and ugly hack that doesn't follow best practices but still demonstrates the core logic for the server:
#!/usr/bin/env python3
import logging
import socket
import sys
import time
from select import select
udp_server_port = 5555
read_buffer_size = 4096
client_timeout = 5
logger = logging.getLogger()
logging.basicConfig(level=logging.INFO)
# socket.SOCK_NONBLOCK does not exist on windows
#udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM | socket.SOCK_NONBLOCK)
# for Windows we can do this instead
udp_server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_server.setblocking(False)
try:
udp_server.bind(('', udp_server_port))
except OSError:
logger.critical(f'Error: Could not use UDP port: {udp_server_port}')
sys.exit(1)
sockets = [udp_server]
clients = {}
expired_clients = []
logger.info(f'Server started on UDP port: {udp_server_port}')
while True:
ready, _, _ = select(sockets, [], [], 0.1)
now = time.perf_counter()
expiration = now - client_timeout
for sock in ready:
try:
data, peer_addr = sock.recvfrom(read_buffer_size)
except BlockingIOError:
pass
if peer_addr not in clients:
logger.info(f'New peer detected: {peer_addr}')
clients[peer_addr] = now
logger.debug(f'Received {len(data)} bytes from ({peer_addr})')
for client_addr, last_seen in clients.items():
if client_addr == peer_addr:
continue
if last_seen < expiration:
# Mark expired client for deletion
expired_clients.append(client_addr)
logger.info(f'Peer has not been seen for {client_timeout} seconds, removing: {client_addr}')
continue
udp_server.sendto(data, client_addr)
# Remove expired clients
for client_addr in expired_clients:
del clients[client_addr]
expired_clients.clear()
its true i tried it
tcp will have more overhead, so you might run into bandwidth limitations faster, but as long as you implement threading properly you shouldn't have issues
a buffer would eliminate any jitter effects
i'm guessing you want to have missed packets to just be dropped instead of waiting for retransmits in this case, right?
hence udp
if it lags here and there
same for video
yes
ima try what you sent
a bit different use of it for when i tried to use select
but maybe just because ur on unix
that's really only going to have an impact when your network link is congested either way, which would cause udp to show issues too
if latency is important for your use case udp makes more sense though
it is
but ofcourse latency would increase the more people connect
but the amount of latency increased was immense
for real-time voice and video streaming latency is everything
from 25 ms to 150ms
didnt work sadly
blocking isnt the issue i guess
got the same results as my own code
x)
yeah, doing this with udp where there is only one socket is quite different from when using it with tcp
just as i said before; i think your main issue is with the client code
i just modified my code above to be more windows friendly
@wise jungle i figured performance was more important than exact timing for client timeouts
that's why i do this in the beginning of the loop after detecting incoming data to not have to get current time and redo the calculation for each client that we are sending out data to:
now = time.perf_counter()
expiration = now - client_timeout
and will probably still be more granular/exact using time.perf_counter() then (time.time() - timeout)
i have not timed it, but in general for this use case i think that this:
for client_addr, last_seen in clients.items():
if last_seen < expiration:
# Mark expired client for deletion
expired_clients.append(client_addr)
continue
# Remove expired clients
for client_addr in expired_clients:
del clients[client_addr]
expired_clients.clear()
will be faster and use less memory then:
for addr in clients.copy().keys():
if clients[addr] < (time.time() - timeout):
clients.pop(addr)
im back sorry was having iftar
yea this is what i was doing
feels better for me to use time.time()- timeout()
why? the loop will not take long for each iteration even with thousands of clients and time.time() is not granular enough anyways
which part?
will be faster and use less memory then:
i want to maximize preformance latency and memory
time.perf_counter() will also get you the most precis time that the platform can handle if you don't need exact time of day and can do with just time elapsed (i think you should be able to in this case)
i see
the you don't want to use copy() and also do the (time.time() - timeout) calculation each time
hoy come
i'm quite sure my longer code will use less memory and cpu than your sorter code
maybe
now = time.perf_counter() will only get the time once for every received packet since i assign it to a variable
expiration = now - client_timeout and then only need to calculate the expiration cut off time once per such loop as well
if last_seen < expiration: just compares the time when we last received data from that client with the pre-calculated cut off time
if clients[addr] < (time.time() - timeout): does that for each client that you are going to send data to for each packet you have received
maybe not yet, but just wanted to highlight the point
also if clients[addr] < (time.time() - timeout) does yet another hash lookup for addr in clients, which my code doesn't do
copy() is also unnecessary slow here if you have many clients as it needs to copy the howl hash once more in memory which both takes time and takes up more memory
for client_addr, last_seen in clients.items(): will avoid doing any further hash lookups and you can compare directly with last_seen
but without copy() we can't modify the length of the hash within the loop
so instead i build an list of those few clients that will have timed out during the iteration of the loop and just after the loop i iterate through the list and remove them from the hash and then clear the list when i'm done
all the small optimizations adds up
yeah, i figured that was why, i'm just showing you another way to do it that is more performant and light on memory
also, i think you can do without storing both self.connections and clients, one of them should be enough
and you're not even using curclients anywhere either
after furthor looking into it i still have to use .copy () @cloud spruce for the way im implementing it
def connectionTimeout(self):
#credit to rndpkt#4407 from discord.gg/python
timeout = 5
while True:
now = time.perf_counter()
expiration = now - timeout
for client_addr, last_seen in self.clients.items():
if last_seen < expiration:
# Mark expired client for deletion
self.expired_clients.append(client_addr)
print(f'Peer has not been seen for {timeout} seconds, removing: {client_addr}')
continue
for client_addr in self.expired_clients:
del self.clients[client_addr]
def acceptConnection(self):
while True:
try:
d, a = self.udp_server.recvfrom(2126)
now = time.perf_counter()
self.clients[a] = time.time()
if a not in self.clients:
print("Getting connection from ", a)
if d == b"connection":
self.udp_server.sendto(d,a)
self.clients[a] = now
except Exception as ex:
print(traceback.format_exc())
def sendData(self, a):
for d in self.serverObj.data_q:
for c, lastSeen in self.serverObj.clients.items():
if d[1] != c:
self.udp_server.sendto(d[0], c)
self.serverObj.remove(d)
all these are gonna be threads
expired_clients can be a local variable in the connectionTimeout(self) function
no need to have it be part of the class instance, you just have to create the empty list before the first for loop in that function
if you have that function running as a separate thread you will have trouble
for one it will run over and over as fast as it can eating cpu unnecessarily due to the while True loop and your not pausing/sleeping for a short while at some point during or in-between iterations
second and much worse is that it's not thread safe as you are changing the dictionary while other threads my use it in a way that is incompatible with the dictionary changing during those operations
you see if someone forcibly closes there connection
they magically get removed
also i tried to do the 2 ports thing and it didnt work surprise surprise @cloud spruce @thorn stratus
Hey @wise jungle!
You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.
not at all surprised π
up late again or just tired since yesterday? π
both
as this is udp you don't really have connections, just peers/clients, which are identified by the tuple (protocol such as tcp or udp, local address, local port, remote address, remote port) those five need to be unique for you to be able to identify a client, but you can mostly ignore the first three and just work with the last two for that
so you aren't really accepting new connections in acceptConnection(), you are just reading data from the listening socket that will be packaged and associated with that socket and the remote address and remote port, again big distinction when you are doing socket programing with udp compared to tcp where you have the abstraction of connections
i think i am "accepting" new "connections"
but
i kind of understand what ur saying
ima try something really quick
hey guys
your not, because you don't know if it's a new client or a datagram from a current client at this point because you have a line
self.clients[a] = time.time()
that breaks your logic of the if statement just after it as you have just set it
so the if statement will never evaluate to true
also, that line where you read time.time() just looks like an accidental left over of your old code as you have my line
self.clients[a] = now
after the if statement, which is where it must be for it to work
what
where is the ti.etime()
are you looking at this
https://paste.pythondiscord.com/soxazokubu
this is the most recent version
where i use 2 ports
i was looking at the code that you pasted above in the channel
no no look at the pastebin
also i think @thorn stratus was write about multicasting
im looking at https://www.youtube.com/watch?v=LnvxObLYO-o
Full Tutorial: https://blog.finxter.com/how-to-send-udp-multicast-in-python/
Email Academy: https://blog.finxter.com/email-academy/
βΊβΊ Do you want to thrive as a self-employed Python freelancer controlling your own time, income, and work schedule?
Check out our Python freelancer course: https://blog.finxter.com/become-python-freelancer-course/
...
yeah, multicast is great for networks that support it, otherwise, not so great π
you see cant i pretty much have 2 "recievers"
but one of them is actually just a sender
You would only be multicasting the voice data back to the clients
is that what u meant
It would be unicast from client to server
with multicast you send one packet and everyone that is subscribing to the multicast group address will receive it and you will never know how many that is
But if you want to do it over the internet you would have to set up tunneling or something similar
hmm
and the one sending the data would receive it as well and must know how to ignore it's own traffic/audio stream
multicast sounds like a huge way to easily breach any voice chat
it was created to send out radio and tv transmissions over the network as well as stock market information
i see
it's a one->many protocol, much like a radio transmission or if you talk in a room
hmm
would there be a way to check who is in the multi cast
you know have a initial connection to check who is in it
and you can't run it between isp:s out on the internet (without tunneling)
even crossing routers will be problematic if they aren't configured to support multicast explicitly
what is easy is just to use broadcast on the local lan, but that isn't too exciting for your application i'm guessing as people will probably not be sharing the same lan and voice chatting just amongst them self with no other external participants
no, it's a network issue and how routing works
so its just both client and server
in multicasting you send traffic not to a clients ip address but to one virtual ip address called a multicast group address
the client then needs to subscribe to that address using a protocol called igmp (not icmp) to tell the switches and routers in the network to give it a copy of all the traffic destined to that multicast group address
between routers it gets more complicated since they need to relay that information amongst each other to tell the next router in the chain about that they have at least one subscriber somewhere behind them and when the last subscriber leaves it signals its peer router that it can stop sending them packets destined to that multicast group address since there is no one interested in them any more... PIM such a protocol, but not the only one
you also have DM (Dense Mode) and SM (Sparse Mode), then you have RP:s (Rendezvous Point:s)
if you where to run it between larger network segments such as AS:s (Autonomous System, you can view them as different ISP:s even if they aren't always) that exchange routing using BGP you got special purpose protocols just to deal with multicast routing between those which almost no one configure, and hence you have no multicast on the general internet
@wise jungle TL;DR don't focus on multicast, use unicast for now unless you have a very good understanding of multicast and can accept all its constraints
i would delete line 39 self.expired_clients = [] and rewrite this function like this (without doing to big structural changes):
def connectionTimeout(self):
timeout = 5
expired_clients = []
while True:
now = time.perf_counter()
expiration = now - timeout
for client_addr, last_seen in self.clients.items():
if last_seen < expiration:
# Mark expired client for removal
expired_clients.append(client_addr)
print(f'Peer has not been seen for {timeout} seconds, removing: {client_addr}')
# Remove expired clients that has previously been marked for removal
for client_addr in self.expired_clients:
del self.clients[client_addr]
expired_clients.clear()
and i removed the continue at the end of the if block since you are not doing anything else in that for loop after that line, so it's superfluous in this particular case
that said, i still wouldn't run it in it's own thread as that code isn't thread safe even by a long shot
and if you insist on running it in a thread i would defensively add a micro sleep within the while True: loop to keep it from taxing the cpu unnecessarily by running that piece of code as fast and as many times it possible can over and over again
yea ima do that
this shit really got me thinking like crazy
networking needs to be reworked
for sure
i enjoy thinking, "i think therefore i am" π
@wise jungle you might want to add a requirements.txt to your project (and the github repo) so that one can do a pip install -r requirements.txt to get all the dependencies install (preferably in a venv of one type or another)
Ok it was indeed a caching issue. When I said "didn't help" I meant that the error temporarily went away but could occur again on subsequent loads. Just now, I thought of outright disabling the cache (through DevTools), which appears to suppress the issue. Obviously, this isn't ideal as regular users wouldn't be doing that. Is there a way I could go into the details and figure out the cause of the error?
Is it always that resource? If it is then there might be some wrong with the HTTP cache headers in the response from the server which you can see using the networking tab
No, it's a random file each time
yuh ima do that
Does anyone know how to solve
Using broadcast. ```
On scapy? It happens every so often when I try to send an IP packet with ICMP (constructed as such:)
IP(dst=...) /ICMP(id=...)
hey @cloud spruce @thorn stratus after trying to fix the code i found the issue and it "works" but its very choppy now
not sure what i have done wrong now π
i got 2 ports
one for listening and one for sending
so, what was the issue and was it in the client?
I want to create a monitor of some sorts that pings multiple hosts anyone know where to start?
you can try ask the question here or if you find a channel that is more appropriate, perhaps #web-development if it pertains to that
How i can use firebase firestore to know who is sending msg to whom and how to deliver the chat to the receiver??(want to make a chat app)
what os are you going to run it on?
if you are going for a pure python implementation you need to run it as the superuser (root on linux, administrator on windoes and so on) as it would require raw sockets
otherwise you just have to run the systems own pingcommand from python, but i think that is a pretty ugly solution to call out to external binaries like that
oh, and it's free too π²
but then you probably want to use end-to-end encryption so that google can't read all the messages
but they will still be getting meta data about whom communications with whom at what time and how much, ip addresses and more probably too
We cannot use socket for sending data
to long distance and and server should be open all if client want to coneected ??that's the prop i can't use socket??
Many people uses firebase for creating chat app.
maybe, i just didn't know it was free until now, it didn't use to be
i wasn't saying you should use sockets
the thing about raw sockets that i wrote was a reply to another users question
and distance has nothing to do with anything here either
Oh yes
Okay
on that note, it's a battery drain on a mobile device to have a socket open all the time from an app and continuously monitoring the socket for incoming data or connection errors such as disconnects and handling them by reconnecting, so a platform specific way of getting notifications from the cloud is much preferred since the platform has it implemented in a way that doesn't drain the batteries too much
Guys if you make a web server in python then do you only need to port forward the port the server is running on for other people to connect?
yes, and you can port forward tcp port 80 (or what ever you are using) on the router/firewall to a totally different port on the server running behind it, like 8080 or what ever you are using
thx
you might need to configure the server so that it knows which port and under which DNS name or public ip address that it's reachable from outside on, otherwise redirects that is generated by the server can point the client to the wrong address and/or port
ight
how many different ip addresses would you imagine to be the maximum number to ping and how often?
what should I do if I see an error socks range must be 0 to 255?? I set proxy and test differents proxies
Between 5-6 and 60s
oh, that isn't too bad, then you could do it ugly by using the systems own ping command and you could do all in parallel
this way you don't need superuser privileges to be able to ping
Is their a way to make it pretty like
ping hostname | Interval 60s | Response:
anymore ideas for my problem
what os are you targeting, or are you aiming for cross-platform?
Linux Debian
we'll see if I have the time to write my own implementation of a simple voice client to test it out my self
alright
Would I use pythonping or ping3
guys is it true that c++ is more widely used for networking than python?
it depends on what you mean with more widely used for networking, for what purpose?
what kind of network programming are you intending to do?
if it's web sites and services then the answer is absolutely no
as memory has to be so carefully managed in c and c++ to avoid introducing security vulnerabilities
if you on the other hand are talking about client applications or server software such as nginx and apache, they are traditionally mostly written in such a language
then you have the "new" kids on the block with golang and rust, where rust can be used as a more memory safe and security focused replacement for c and c++
for web sites and web services a lot is developed in python and to some degree also in golang (googles own programming language also just called go a lot of the time)
but one of the most used languages is still php, unfortunately... probably because there is so much legacy applications written in it
php has seen a lot of security vulnerabilities, but mostly not in the core language but in the frameworks and libraries used and a lot of old unsecure code being reused because people are reusing old code and solutions they find on sites like stack overflow that can be really bad and without really understanding the code before the use it
just to take one example; php got support for placeholders/bind variables for sql (which is a security critical feature when using sql) very late in it's life
so there is still a lot of php developers that doesn't know about them or how to use them, hence a lot of security problems with that kind of code
of course there is stellar php developers as well, but the are dwarfed by the share numbers of junior developers that just use the above mentioned legacy stuff which leads to an even worse reputation for the language
Yeah my school is teaching php and I can feel the difference between a modern one and this one
too bad for you that they haven't chosen better π
Hmm...
im currently trying to ping my mc server an get current statistics with the code of
from mctools import QUERYClient
query = QUERYClient('play.bobbot.uk', "2894")
stats = query.get_full_stats()
print(stats)
with the error of
OSError: [WinError 10040] A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself
is anyone able to help?
seems like a bug in mctools. probably report an issue to them
okay thank you
how can people from outer web connect to my websocket server?
i was testing a websocket server today with a friend and he tried to connect but it didnt work.
i have the corresponding ports forwarded, and filtered in the firewall. i know this cuz we tested it today too and i had a mc server awhile ago. plus regular sockets work just fine.
a small javascript-embedded html file (messenger) works fine for me on localhost, but it doesnt work for my friend.
Port Checker is a simple tool to check for open ports and test port forwarding setup on your router.
Verify and diagnose connection errors on your computer.
will this not work?
or is that site any different
yeah but
the port is 5050
the open port i mean
how will this site know which port to check
not really
no
i have the port open
how can that ping
determine it tho
oh
hm
but he could
lol
he did
with nc
and regular sockets
yes
lol
we tried it literally today
its a websocket thing
it works on localhost
its literally open
and ncat works
has anyone else had this issue?
i mean
the same thing here doesnt work with the websockets thing, but that could be because its.. well websockets and not regular sockets
its ws:// something
poof
now it look like im talkin to myself lol
tcp is still tcp, the underlying socket won't "care" if you run something called websockets (they are two completely different things and only related in name, kind of like java and javascript doesn't share much relation) ontop of that or any other protocol which could also run ontop of tcp
oh true, what could be the issue then?
protocol inspecting firewall could be one thing, even though unlikely
local host firewall in your os that will not permit external connections
and quite a few more reasons
i even disabled firewall competeley
and i have like everything allowed om 5050
on*
tcp and udp
how does your bind line look like?
and what is the value of the variables used in that line if any?
do you want to see the client or the server?
just the relevant lines of the server will probably suffice for now
ok ill see
server.py
...
from websockets.legacy.server import Serve
from websockets.server import WebSocketServerProtocol as Wssp
class Server(object):
def __init__(self,
host: str = "localhost",
port: int = 5050,
*,
loop: asyncio.AbstractEventLoop = None) -> None:
self.__loop = loop or asyncio.get_event_loop()
self.__host = host
self.__port = port
self.__clients: set[Wssp] = set()
self.__server: Serve = websockets.server.serve(self._client_handler, self.__host, self.__port)
async def _client_handler(self, ws: Wssp, path: str):
self.__clients.add(ws)
rgbprint(f"[+] client connected! {ws.local_address=} {ws.remote_address=} {path=}", color="green")
while True:
try:
msg = await ws.recv()
rgbprint(msg, color="magenta")
for client in self.__clients:
if ws is not client:
await client.send(msg)
except websockets.exceptions.ConnectionClosedOK:
rgbprint(f"[-] client {ws.local_address=} {ws.remote_address=} disconnected", color="red")
break
def run(self):
rgbprint(f"[+] listening for connections on {self.__host}:{self.__port}", color="green")
self.__loop.run_until_complete(self.__server)
...
part of the client
ws = new WebSocket(`ws://${host}:${port}`);
WS.onopen = () => { alert("connection success") };
WS.onclose = () => { alert("server closed connection") };
WS.onmessage = (evt) => {
console.log(evt);
add_message(evt.data, "Stranger: ");
};
oh, abstractions... but i think i see the issue and it's my more likely guess i was getting at
don't set host to "localhost", then it will probably just listen to 127.0.0.1 and not be able to accept external connections on that
just set it to None, the empty string or even 0.0.0.0, i think any one of them will work
those three are in most cases equal
some people like to bind to socket.gethostname() but then they're just listening to one of the interfaces and it might not be the right one if there are multiple (virtual ones included)
your welcome, hope things works better from now on π
yo @cloud spruce any updates
I'm using the builtin socket library and how do I know if a client has disconnected?
It needs to handle any disconnect. So I can't send a disconnect message to the server
There must be a better way then pinging the client every n seconds
udp or tcp?
tcp
sorry, still haven't had time to sitt down and write that amount of code that isn't work related π
there really isn't, just think about it, how do you really defined "disconnected"?
the os will notify your program that is holding the socket as soon as it knows, but it will usually take time before it knows unless it has gotten explicit disconnection or some other error from the peer or a device anywhere along the path
also consider how long time your computer will attempt retransmissions, many times you'll want to set up a shorter timeout than that your self and declare the connection to not be fit for use anymore if it takes longer than that timeout
There must be a better way then pinging the client every n seconds
From the way you phrased it, it seems you're making your own "keep-alive" packets, even though you're using tcp.
It already handles that for you.
with udp you might not even know depending on the protocol being used ontop of udp and udp is connectionless, take syslog over udp for example, it is a one-way protocol so you will never know if anything is even received on at the destination
I mean, if the client explicitly disconnects (FIN/RST), a .read() will return empty once
not strictly true, TCP doesnt implement this (and a tcp connection can theoretically be open forever without sending any data) however your operating system can be (and usually is by default) configured for TCP keepalive to check the connection is active by sending a packet and waiting for an ACK
tcp built-in keep-alive is very unreliable as it has a system wide interval that the standard strongly suggest should be two hours and it is very discouraged to ever change/tweak it, with retransmission timeout ontop of that you are looking at more then two hours and fifteen minutes
in today's networks there are often many network middle boxes that keep state for NAT (firewalls, load balancers, transparent proxies and more, sometimes even routers with more functionality then just basic routing) or just firewalling in general which many times silently removes its connection entry after a much shorter period of time, 60 minutes is very common and even 5 minutes
yeah, you can easily disable tcp keep-alive for your sockets and they many live for as long as the system does if it's not used to send any traffic, as it can't detect being disconnected any other way (other then being notified by another system which i already mentioned above)
I'm probably conflaing one thing for the other, but then how can one end detect the other went down instantly (for all intents and purposes) and propogate the error up to the application?
it doesn't without the system going down notifying the it's peer about the fact before it goes down or if you are sending packets and you don't get acknowledgments from the peer that it has received the traffic within the timeout you have set in your application, or if you haven't it's the tcp re-transmission timeout for all retries, that will take quite some time
normally when one peer wish to end a connection it sends a FIN (finished) packet, that only tells the other peer that we are done transmitting data on the socket but we are still listening for incoming data, hence we will still be sending ACK (acknowledge) packets (but no data on the connection) to the other peer that we have received it's packets, then the other side should do the same when it is done sending
if one wants to terminate a connection one sends a RST (reset) packet to the peer, that means that we will not use the connection anymore and we won't be listening to it either, this is typical for critical errors and such but used for a lot more than that
Hmm, are you saying that if the os detects that a process that's using a connection encountered a fatal error / was killed, it will send an RST packet since the underlying connection still holds?
Otherwise I don't see how going down hard and still managing to send a packet can mix up.
that is up to the os implementation, but generally yes
Damn, I love operating systems.
it's the tcp stack in the os that is actually managing the connection, not the application unless you use raw sockets and implement tcp or another protocol on those in your application
surprisingly, it sent FIN when I SIGKILL-ed my program:
$ nc raylu.net 80
$ killall -9 nc
$ sudo tcpdump -nvi wlp2s0 'port 80'
tcpdump: listening on wlp2s0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
15:18:14.790816 IP (tos 0x0, ttl 64, id 56227, offset 0, flags [DF], proto TCP (6), length 60)
192.168.1.211.41500 > 172.67.179.42.80: Flags [S], cksum 0x4e18 (correct), seq 2039171453, win 64240, options [mss 1460,sackOK,TS val 314664151 ecr 0,nop,wscale 7], length 0
15:18:14.811747 IP (tos 0x20, ttl 52, id 0, offset 0, flags [DF], proto TCP (6), length 52)
172.67.179.42.80 > 192.168.1.211.41500: Flags [S.], cksum 0x28f9 (correct), seq 949651015, ack 2039171454, win 65535, options [mss 1400,nop,nop,sackOK,nop,wscale 10], length 0
15:18:14.811836 IP (tos 0x0, ttl 64, id 56228, offset 0, flags [DF], proto TCP (6), length 40)
192.168.1.211.41500 > 172.67.179.42.80: Flags [.], cksum 0x679c (correct), ack 1, win 502, length 0
15:18:17.643954 IP (tos 0x0, ttl 64, id 56229, offset 0, flags [DF], proto TCP (6), length 40)
192.168.1.211.41500 > 172.67.179.42.80: Flags [F.], cksum 0x679b (correct), seq 1, ack 1, win 502, length 0
15:18:17.665118 IP (tos 0x20, ttl 52, id 53436, offset 0, flags [DF], proto TCP (6), length 40)
172.67.179.42.80 > 192.168.1.211.41500: Flags [F.], cksum 0x6950 (correct), seq 1, ack 2, win 64, length 0
15:18:17.665188 IP (tos 0x0, ttl 64, id 56230, offset 0, flags [DF], proto TCP (6), length 40)
192.168.1.211.41500 > 172.67.179.42.80: Flags [.], cksum 0x679a (correct), ack 2, win 502, length 0
there is so much that is going on in the different layers of the network stack that most users aren't aware of, and that's kind of the point, it should just work, but as a developer using network communication it's really powerful to know how the different layers work and interact with each other
no idea who shichao is but this page that I just found is great https://notes.shichao.io/unp/ch7/#so_linger-socket-option
Yeah it is fascinating, I'm kind of looking for a resource that touches on all those nitty gritty details, but all I can find are acursed abstractions and high level overviews.
Would you happen to know of any?
this is the RFC standard and authoritative source that implementers must follow if they want to be complaint: https://datatracker.ietf.org/doc/html/rfc793
but one might want something a bit lighter like: https://en.wikipedia.org/wiki/Transmission_Control_Protocol
there is a lot of additional RFC:s that should also be implemented on top (extensions, added features, etc) of that to function in today's networks, but that one is the main one for tcp
Read that, maybe I'm just not letting the information sink in, but i'll check out the other recources.
Thanks anyways.
Oh boy that site doesn't have presentation on their priority list I'm telling you.
if you are talking about ietf, no look at the age of that (1981), it easily predates html, it was just text files and they have mostly just published them on the web
yeah, i never said it was light reading π
@earnest blaze that's also another thing, sockets are not the same as tcp, original bsd unix (not the flavors of today) use to be the reference for that
sockets is just an api that generally the os exposes to its applications for them to use those services that the os handles
I'm a little confused with how python and networking works. I'm making a chat server and looking at reference from other peoples work, they tend to send their messages with some sort of escape character such as \n or >> for example. But my main concern is how can someone like a user type those without cutting off the rest of their message? It probably works very differently but thats why I came here for help. Any information or resources to start are needed. Thanks!
@normal gazelle if you delimit messages with a newline like IRC, you just don't allow messages to have newlines
otherwise, you need to specify the length of the messages (and don't use a delimiter)
realistically, in 2022 if you build a chat service, you're gonna want to use websockets for all your communication so you can support a browser client. websockets take care of framing for you so you don't have to worry about delimiting/length
hmmm alright, I'm not going to use a delimiter then, I'll just make a custom protocol. I would use websockets, but it would be a good experience doing this anyways, it would give me a better understanding and practice. Also, I want to check the message length from incoming messages but I am having a few issues, the first one mainly being packet fragmentation, currently I am sending data as a json, checking if the first and last index are brackets, then i am converting the string into a dictionary. I then check if it has the right keys to prevent any errors etc. This works pretty well so far but I was wondering if you are anyone had any input.
JSON is not a great wire format. I'd use the struct module, which helps you encode strings with length
you can't just check for a closing brace at the end. if you have a nested dict, you might find that brace
and remember, tcp is a stream. nagling means 2 send calls from the peer may get grouped into 1 recv call on the other end. fragmentation means 1 send call may result in multiple recv calls. you must always delimit or specify the length of your packets to frame them (or use something higher level that takes care of framing, like websockets) @normal gazelle
should i keep this where i use a new socket for every message or just have one or a few sockets staying open for each machine i'm connected to?
class Server:
def __init__(self):
HOST = socket.gethostname()
PORT = 8080
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.bind((HOST, PORT))
self.sock.setblocking(False)
self.conns = []
def poll(self, addr):
self.sock.listen(1)
read = [self.sock, *self.conns]
readable, w, e = select(read, [], [])
for sock in readable:
if sock == self.sock:
conn, addr = self.sock.accept()
self.conns.append(conn)
print(f"connected to {addr}")
elif sock in self.conns:
data = sock.recv(1024)
print(f"received {data} from {sock.getsockname()}")
sock.close()
self.conns.remove(sock)
del sock
if __name__ == '__main__':
s = Server()
while True:
s.poll((socket.gethostbyname(socket.gethostname()), 8080))
||disclaimer : this is not production code don't worry||
I mean if you are going to continue talking to the other clients then I would just keep them open, or else they would have to constantly reconnect etc
it just depends I guess..but I would just keep them open until you are done
ok thx
@deep surge in addition to not reconnecting, I'd suggest not recreating the read list for select and using selectors instead
also, super weird to call listen more than once and dangerous to set the accept buffer to something so low
huh? but don't you need to call y = n*listen(k) for y amount of connections?
you need to call accept for each incoming connection but you only need to call listen once (and I'm surprised you don't get an error calling it the second time)
ok but how much to i set the accept buffer to then?
oh, lastly, use SO_REUSEADDR. the socket docs have an example of this
some number at least add high as [the rate clients can connect to you] - [the rate you can accept connections at without falling over]. probably at least 16?
Anyone here currently enrolled in the WorldQuant data science lab?
raylu, would you mind giving me some examples. I am totally lost
Im honestly almost at the point of using web sockets but I want to try and solve it without it first and try to understand it
What are the best python libraries for finding and using proxies?
@normal gazelle ok.... the struct module is not nearly as helpful for variable-length strings as I thought
so I think your options are
- the above ^
- something like protobuf (at which point you might as well just use gRPC)
- websockets ;)
I guess
0. use fixed-length strings
I'm going to try the packing / unpacking, and if that doesn't work. Web sockets it is
thanks
(I got my start doing this sort of thing for battle.net 1: https://bnetdocs.org/packet/307/sid-chatevent)
ok so i read this self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
but what does it do? it says it has something to do with timeouts?
without it, try stopping your server and then restarting it immediately
ok i think i see what you mean
ok so i just read the selectors doc page, and why is it better? isn't it just more boilerplate?
you can reuse the selector across iterations of the loop (and just add/remove client connections as needed)
also, it can use a better select implementation under the hood
it's not more boiler plate
it's an abstraction, yeah
i don't get it
oh wait i think i get it
well is the performance difference major? i kinda prefer it like it is now
I mean, the real perf problem is gonna be blocking/slow calls in whatever you use to handle your connections, so no
ok well i think i prefer staying on the base select module. anyways thanks for your patience
dunno what kinda time i'm bothering at but here it's 3.5am
Has anybody worked with p2p networks that utilize a rendezvous server? I'm looking to work with py-ipv8 but I'm not sure if there are good alternatives before i dive.
hi, any good resources to learn distributed systems? tutorials/books etc...
Hey @ember ledge!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
Hello how would I establish a connection over the internet using socket. I would like to make my game a multiplayer game. Thanks.
you would probably need to create some software to act as a game server and then the actual game would be the clients that connects to the game server, otherwise you will probably get problems with NAT on the players home routers
okay, can anyone help me with sockets?
what do you need help with?
my_id = '844926742317367318'
url = 'https://www.repscore.app/'
xpath_search_bar = '//*[@id="id_input"]'
xpath_confirm_button = '/html/body/div/div[1]/div[1]/div[4]/div[2]/a'```
Hello, I have a quesion about automating scripts.
I would like to do the following:
1οΈβ£ open https://www.repscore.app/
2οΈβ£ insert my ID: "844926742317367318" in the search bar.
3οΈβ£ store the result as a variable list_1
So what's the problem?
What are you expecting to get for a result too @ember ledge ?
@wind oriole first of all, as you might see on the code; I don't know how I can get Python to control my browser(Chrome, Firefox...).
Second; the code is just wrong, because I don't know what the commands are to do the steps (1,2,3).
Lastly; after step 2 there will be a search result that should be stored in the variable list_1.
K so, bear with me, on mobile
To control a browser you need Selenium
From Selenium you would import webdriver
Then...
driver = webdriver.Chrome()
driver.get('https://www.repscore.app/')
That will send a physical browser to that page
To find the search bar....
search_bar = driver.get_element_by_xpath(xpath_search_bar)
Then you need to send your text to it
search_bar.send_keys('blahblah')
Find the button the same way
And use button_variable.click()
But if the value you're looking for isn't on the page that follows, you're gonna have to use Selenium-Wire instead
so...I decided to test out my chat server latency and I came across an issue, for some reason once a certain amount of messages are being sent everything stops, all connections are closed and it stops making any new coroutines. When the actual clients themselves try to connect they can, they just cant do anything since no functions have been started, this is my start server function. ```py
server = await asyncio.start_server(handle_client, 'localhost', 9090)
print('Server is listening...')
async with server:
await server.serve_forever()
Join me in this fun interactive session that will help you in exploring Data Analysis and also walk you through the details of the Microsoft Learn Student Ambassador Program.
Key Takeaways:-
-Introduction to Microsoft Learn Student Ambassador
-Overview of what is Data Analysis
-Creating Microsoft Excel Dashboard
-Introduction to Microsoft Power BI
-Quiz and Giveaways
-Q&A
EVENT DETAILS -
Date - 8th May 2022
Day - Sunday
Time - 5:00 PM IST
Duration - 1 Hour
Platform - Microsoft Teams
Event Host - Aditi Gulati (Alpha Microsoft Student Ambassador)
If anyone is interested then DM for registrations
!rule 6
@ember ledge please follow the rules
Why is a network splitted in WAN-zone, LAN-zone and Guest zone??
you can split a network in as many or few zones as you want or need to, a few of the most common names for such zones are:
WAN (Wide Area Network) is just what you usually call the internet side of a gateway or firewall, that connects to the wider network
LAN (Local Area Network) is often the network within a building, apartment or what ever smaller area like that where you have your client desktop, laptop, tablets and phones on, even some internal servers that you don't want anyone from the internet to be able to reach
DMZ (DeMilitarized Zone) is where you would put your servers on that you want people both on the LAN and WAN (i.e on the internet) to reach, but still have them on a separate segment protected by a firewall
Guest zone is mostly for people that you want to be able to give internet access to through your internet connection and often they can reach the resources on the DMZ as well, but usually they are not able to reach anything on the LAN
Does anyone have any information on application protocols? I'm working with Sockets and Asyncio using TCP as my network protocol and I need to be able to check if the message has been split / fragmented, re join or separate the messages in the stream if something were to happen. Not sure what I should do. I would use Websockets or something like HTTP , but Im not, so that's out of the question. Maybe I should just take like a 2 month break and study networking? Idk, any information is helpful
you will never know using a stream socket the os is handling the heavy lifting in that departement, that's kind of the point
you just read a stream of data over and over until you think you have at least enough to process one message, action or what ever
if you want to invent your own application protocol ontop of tcp the two most used methods is to either use a header which encode a length field for the following message or you use some kind of delimiter which doesn't need to be just one byte, http for example use a combination of both approaches
hmmm okay, So can you tell me if this sounds right? This is what I plan on doing (maybe)...Add a header of the length to all messages. When the server / client receives those messages , read up to the specified header length. If there is more information after that, check if there is another header and read up to that data and so fourth.
or I could use the delimter method, where I could just replace a certain character with an off limit one, then add the original as a seprator and revert it once recieved
nvm, I'm gonna do some research
yeah, but I would read a larger chuck from the stream and then work with an internal buffer in the application, but other than that I think that is how I would do it using that method
alright thanks, also. Do you think you could help me implement it? If not it's fine, I'm just not sure the most efficient way considering I'm using asyncio
almost, think about how you use \ your self in strings in code, that illustrate this method very well, there \ is the special code point followed by what ever byte comes next and if it's the same character again then it represents that literal character
if using that character (or any other uncommon charachter) you could scan the input for it and doubled it, then after the encoding/escaping of the string you add your special end of message combo at the end, let's say \e in this example
when receiving you just reverse the process (in the reverse order)
oh, that makes sense...and you would just probably use something like a for loop or something with a step of 2 so you can check every other pair
hmmm...so should I make something like you suggested or something like netstring?
I also don't want a ton of try catches hindering performance so I'm not sure
i think using a length header would be the most performant of the two, while using delimiters would be the simplest to implement
okay, also for the length header, would it be better to add aome sort of padding..like : 013 or something...or should I just use no padding and check for a colon or something
for a header you also have two choices, either go with a constant length header or delimiter which in that case can never occur inside the header (this is just how http do it with two consecutive new lines to form one empty line, but you could use what ever you want for your protocol)
but padding as such should not be needed
of those two, the constant length header would be the most performant but add a restriction of the length of one message due to the maximum length of bytes that would be able to be encoded in the header
this was for a chat application, right?
unless it's a end-to-end style where you connect directly to the other party, i'm guessing you would like to encode the recipient and sender of the message in some way as well
the client first has to encode the intended recipient of the message somewhere
if using a server you might want the server to add the username or user id of the sender (doing this server side to avoid spoofing of senders by the client) to the message before relaying it to the recipient
it's a chat server yeah, and for spoofing, the only thing they can spoof is thier ip
on initial join their username is mapped to a writer that I check each time before broadcasting information
so that you can tuck there username or user id on to the message before broadcasting it i assume, right?
where are you adding the username of the sender?
you got a header field for that already or do you just append it to the start of the message?
Well, currently I have it where it requires a username to start the loop that accepts user input, so just a single receive, then once that gets added it starts up the loop eyc. I will probably change it though
Hey,
We are looking for an addition to our team. We previously were some of the top performers in online Poker and have transitioned into trading and managing cryptocurrencies early last year.
Our goal is to find someone code-agnostic who can help build and support various apps, ranging from simple automation to penetration-testing to full-stack-development. But, most importantly, we are looking for someone eager to learn, a problem-solver who is excited to take on new challenges and grow together with our team.
Preferably you have experience with reverse-engineering tasks and participated in relevant events/competitions. If this sounds interesting to you and suits your set of skills, please reach out on Telegram @onyx willow12345.
Thank you!
!rule 9
@onyx willow this is not a job advertisement board
okay, so I haven't really made any thing invoking headers with streams yet so how would ingo about this? Would I just create a receive call that waits for the length being sent first, then on the second accept that many bytes?
since the streams have guaranteed order
length = (await reader.read(5)).decode()
data = (await reader.read(length)).decode()
``` it's probably not right, but better to ask than be confused
i guess that would be for a constant length header if you chose that as your solution?
and when you read you could get that many bytes or less, so you need to put the read in a loop that ends when you have gotten that many bytes that you are expecting, unless you make your own abstraction of read and do that part in there
would i have to use a delimiter for a non constant length?
yeah, a kind of delimiter but for the header in that case
I plan on limiting messages below a certain limit so I'm not sure if it would cause more issues having to try and re assemble streams etc
a message cap on the server side
if you are going to have a permanent limit for the maximum message length you could go with a constant header as you might not need the flexibility of a variable length header, but it does limit the future extensibility of the protocol, which might be fine for your application
well, I might as well make it flexible in case I wanted to use it for something else...so....what should i use for my delimiter?
guys anyone here who knows how to connect pyzmq client to a websocket server?
just remember that flexibility also means much more complexity and at this point i think the complexity might now be worth it
I agree...well...thanks for the help today. I'm going to do some research and figure out a way to implement this
just remember how recv() on a socket works, that it doesn't always return the number of bytes that you have requested, you have only specified the maximum number of bytes you want to read
or are you using some other library then socket?
guys anyone know how to fix this Traceback (most recent call last): File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 750, in transfer_data message = await self.read_message() File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 819, in read_message frame = await self.read_data_frame(max_size=self.max_size) File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 895, in read_data_frame frame = await self.read_frame(max_size) File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 971, in read_frame frame = await Frame.read( File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\framing.py", line 85, in read data = await reader(length) File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\asyncio\streams.py", line 723, in readexactly await self._wait_for_data('readexactly') File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\asyncio\streams.py", line 517, in _wait_for_data await self._waiter asyncio.exceptions.CancelledError
client ! failing OPEN WebSocket connection with code 1006
client - event = connection_lost(None)
client - state = CLOSED
client x code = 1006, reason = [no reason]
client - aborted pending ping: d26ad5c7
client x closing TCP connection
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 750, in transfer_data
message = await self.read_message()
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 819, in read_message
frame = await self.read_data_frame(max_size=self.max_size)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 895, in read_data_frame
frame = await self.read_frame(max_size)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\protocol.py", line 971, in read_frame
frame = await Frame.read(
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\websockets\legacy\framing.py", line 85, in read
data = await reader(length)
File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\asyncio\streams.py", line 721, in readexactly
raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.IncompleteReadError: 7763702 bytes read on a total of 16797496 expected bytes
hey how would i allow multiple clients to connect to one server using socket
and each send their own stream of packets
Can you send an example file about printing the value from the html websocket api to the console with python socket?
hey i want to make an online turtle game what would be the best way to implement the multiplayer part? have the server send position packets to the clients or maybe have it send directions to the client. I have already made a server and a client and can send messages to and from them i have also already implemented a username system but i dont know how i should go about syncing the movment of turtles across clients any help would be much apreciated
yeah have the server keep track of players x,y...and eventually you could have it only send the ones on the actual screen
instead of all of them
Hi I'm trying to send files through sockets but it keeps saying
No such file or directory: ''"
File "C:\Users\scrip\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\scrip\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\scrip\Desktop\SpotifyGen\main.py", line 26, in client
readfile = open(f, 'w')
FileNotFoundError: [Errno 2] No such file or directory: ''
nvm fixed it
asyncio, but im pretty sure it uses sockets deep down
since it has almost all the same methods in the loop
yes, it does, but i think the code looks quite different using that abstraction
what do you mean by the code looking different? Like how the sockets are used?
Hello!
i am sending a broadcast packet out but do not know how many devices will respond back. How do i count how many UDP packets were received?
received on the sender or receiver side?
I send out 1 broadcast packet, 0 or more devices will respond with a broadcast packet
but i wont know ahead of time how many devices will respond
Use the wireshark for packet capture at source and destination end.
but i am automating this and dumping the data into prometheus
i can make it non blocking and then catch the exception but it would be best to just know if their are packects in the socket ready to be processed
What are you looking for? Just a basic counter in total? or something like a dictionary with the amount form each one etc?
ill work with what ever is recommended
you could probably just get by using a while loop and a recv call
ive made the socket non blocking as i am sending out data to select of interfaces
i am unable to tell if the socket as a packet to be recieved
i get this error if i call recvfrom when no data is available
BlockingIOError: [WinError 10035] A non-blocking socket operation could not be completed immediately
well yeah, it might get dropped etc
if you are looking for confirmation I would use tcp
Check with your network team that it could be possible if the ACL is not allowed for that particular udp Port.
i kinda thought i could read the buffer size
i am hobby coder
no network team
i recieve the first packet just fine
it comes in as a byte array, but then i am unable to know if additional packets are avilable
that error comes up when i recvfrom and no packet is in the buffer
but sometimes i will send broadcast and no devices will be online to respond. so i will want to check for that
i am doing this ```
data, addr = sock.recvfrom(1024)
print(data)
b'\x01\x02\x00\x00\x00\x00\x00\x00l\xb3\x11@>\xd2 \x0c\xc8=\xb8\xde\x00\x00\x00\x00NSDP\x00\x00\x00\x00\x00\x01\x00\tJGS524Ev2\x00\x03\x00\x08switch01\x00\x04\x00\x06 \x0c\xc8=\xb8\xde\x00\x06\x00\x04\xc0\xa83\xf0\xff\xff\x00\x00'
data, addr = sock.recvfrom(1024)
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
data, addr = sock.recvfrom(1024)
BlockingIOError: [WinError 10035] A non-blocking socket operation could not be completed immediately
i think i will just put it in a try, give devices a second to respond and then recfrom untill i get an error :\
you don't want recvfrom you want recv as you don't know from which ip address you will get the response packet from
i thought recv was tcp and recvfrom was udp
yup i read recv is for tcp
The recv() call is normally used only on a connected socket (see connect(2)). It is equivalent to the call:
recvfrom(fd, buf, len, flags, NULL, 0);
your right, i mixed up the two
i am going to keep playing with selector to see if it will notify on packet
it is late though i need sleep
you're on windows too, aren't you?
i am writing this on windows but will run it on ubuntu once finished
honestly if it does not work i am thinking of reading more into twisted
i try to not rely on try/catch
aha, because i saw that you wrote selector, which is kind of a abstraction of select
select apparently doesn't work very well on windows but on linux there is no problem
for what you are doing asyncio sounds like it would be a good fit
what kind of netwroking can you do with networking in python
That's very general- all sorts, I suppose
mhm
rather, what are you after?
anyone used netmiko before ?
hello someone here knows about socket programming?
do you have a question?
Try taking out the space after the comma in line 5 in between ((serverName, serverPort))
It's just a guess, but all examples I've seen don't have the space after the comma
@jovial trellis hola wapos server is definitely not a valid hostname, which is what the error is trying to tell you
F
well i did the changes and now works thx π
What was the fix exactly? Was it the server name? because my suggestion was downvoted lol
that space in the code does nothing other than make the code look a little better (increases readability), but it will execute the same
that has absolutely no effect on anything
it's just styling
Hey there. Ive been working on a game framework in pygame and have began working on the server application. I see a lot of tutorials for simple programs but since my framework is quite robust im having difficulty figuring out how I want to set all this up. My current idea is to have the server program be a modified game client, one that does not render sprites or take controller input. This way, I can spawn game objects on the server the same way I spawn them in the client. My plan is to use pickle to send entire game objects between the server and back. This "server client" runs 2 threads, one for accepting and managing client connections and the other is for game logic. I've never designed a network framework like this before so this is new to me, am I taking the wrong approach to this?
@fossil fiber pickle is not generally suitable for network communication. I'd probably come up with some other representation for objects on the server and some other protocol for serialization (https://docs.python.org/3/library/struct.html or protobuf). only use pygame for rendering
Oh I see, thank you. I will take a look. Im guessing struct.pack is the equivalent to pickle.dumps, as struct.unpack is the same as pickle.loads?
Struct won't serialize objects for you the same way pickle would, so it doesn't make sense to compare them as equivalents. I'd refer to the example at the end of the page for a better idea of what struct does do
I guess the reason it was recommended to you was to make it simpler to encode and decode data over the network connection, but you'll still have to manually decide how to encode game objects into a transmissible representation, and decoding them back into game objects
So sending all game data is not a good idea?
on a similar note, what if my player object has an attribute weapon for example, and its of type game object. I cant send a whole other game object within the attributes of an outer game object can I?
although it still is in the master list of game objects so i guess I would just package that seperately
It's a shame there arent more complex examples for this kind of thing, and if there are, someone please show me, like maybe a write-up or something
Ideally for a smoother experience you minimize how much data you send in general, because the more data, the more likely it is you'll run into problems.
A blind encoding and decoding is also a lot more susceptible to being compromised because you don't check the data or what it's doing at all. The docs for the pickle module says as much.
This is hard to answer without knowing what you end up using to encode your data
If you use pickle, it'll encode everything from the top down, so any nested objects will be encoded
If you write your own encoder which doesn't send as much data, that'll be entirely up to you
I think writing my own encoder is the better direction from what you tell me. Since nested objects are still in the master objects list, sending it from both the parent object and the master list would probably send it twice, so thats no good. Any documentation on custom encoders?
If my experience from other engines ive used is anything, im guessing some sort of replication system is in order? I guess im just having a hard time understanding how I would specifically send object data from client to server and back, but that all depends on my framework so its not something I could really just ask in a public server
For the sending part specifically, there are many ways. As Raylu mentioned, structs are designed for this purpose (writing and reading binary data into a known format), but there are many methods.
In terms of your encoder, this is kind of hard to say because it'll depend on what you want, and what you want is even more complicated because you're trying to build an engine. You'll have to make some calls here about what you want your engine to do. Sending only metadata (such as what weapon is equipped instead of the entire weapon) can be useful, but it can be limiting (can't make more complicated leveling/upgrade systems without creating many copies of the same weapon for instance).
Sending metadata is probably too limiting, since its funny you should mention it because complex upgrade/level systems are the main point of my current project. Although I am working on this infrastructure to be broad for use in other projects, I imagine it will change drastically depending on said project, so specifics can be tuned to the game i'm working on now.
So the general stance I (think) I'm understanding here is initialize game object data on the server, send it to the client. Client modifies that data, sends it back to the server, and spreads that data to the rest of the clients. Does that mean things such as physics calculation (for things like projectiles) and game logic (scoring, player management) should be done on the server? in that case, is the client only really for rendering and taking input?
Unfortunately another case of "that question depends on context" haha. In some cases, you'll want to do those calculations on the server, either to reduce client load, or prevent cheating, or w/e else. Some things you'll want to do on the client. For a game engine, it might be good to provide the user with ways to do either, so they can choose whatever is best in their given context
I see, this has all been very helpful to me so far, thank you. The point of the server being a modified client is to allow for the freedom to do whatever, wherever, but the unfortunate reality of me doing that is I don't know where to go or what to do after lol. Differentiating what data goes where is the real learning curve for me here. I've already established a network <-> client relationship with a simple socket server, but what data needs to go between them is a challenge in itself. I will find out as I go. Thanks again for your help.
in general, networked games send only a delta rather than updating the entire state @fossil fiber
FWIW, this is a pretty complicated topic. like, how sensitive is your game to latency (do you need to do interpolation?)
Hey, Any recommended practical tests on Netmiko or Napalm? Been recommended - https://www.packetcoders.io/
To be honest, I'm not sure. It runs 60 fps well on my worst device, but I'm not familiar with that term
not frame time. I'm talking about network latency
Again, I'm not really sure. I havent programmed a way to send game data back and forth yet, all I have are clients connecting to a server and sending a confirmation back and forth.
And, a game framework
like there's a "finished" game but its purely client side
Guys, I kinda really need help with a project.
Anyone can help me please? I am starting in this language and it has been complicated. maybe someone can give me a light
Thank you so much.
Describe your problem.
So, I need to create a roulette bot. Which will look for the past 4 rolls, and send a message to telegram. That's it basically.
But with my skills of webscraping using selenium. I was not able to even get the information from the page
I tried using pyautogui to look for images( when its 4 same rolls) But I could not run it in a AWS like
forever
24/7
So I gave up for now.. I have no idea how I will be able to do that
Does it make any sense anything I said
Hello, I'm no programmer but I'm familiar with fundamentals such as data types, variables, array, loops. I want to learn how to view packets and read them, what steps should I take? I searched on google and there's thing called "Wireshark" about packets, should I learn how to use packets? Am I in the right track about my goal?
Wireshark gets stuff going through your network
What packets? U mean packets going through your network?
Yes
Coming to my pc
Packets coming to my pc
I want to collect those packets and read them
I just have an idea to track something and analyze it
Am I in the right track?
If I'm going to learn wireshark?
Yeah! I think that wireshark is a good idea
If you are able to filter the thousands of packets running
xD;)
I want to collect data from a game
I dont want to do it manually
So I researched and there's thing called packets
So I look about packets
And that's when I discovered wireshark
hello, how can I make client and server side sockets communicate on different networks?
I've triend putting my ip found on whatsmyip, but it doesn't work
can you ping your IP?
whoevers running the server needs to port forward
when u run the server just use 0.0.0.0
and then to connect to it you use the public ip and port
@timber zodiac wireshark is good if the structure of the packets is simple (and unencrypted). otherwise, you might be better off disassembling the game (assuming windows, using x64dbg or ghidra)
yes
how can i do that?
i dont know
no
i asked
its a setting in your router, open your router settings and their should be an option
you should probably look up a video
okay
on how to port forward on your router
is it risky leaving it opened?
can I just "port forward" my device?
my specific local ip
if you dont have a process running behind the port listening, connections will bounce off anyway (not a security risk)
if you do have a process running then the security is based on the implementation of the process
I am not talking about my program
Im talking about the router
(I am new to networking)
no dont worry
No it should be on advanced settings
And then just port forwarding
If your router/network is new you probably dont have a static ip and probably have a cgnat
Where you cant port forward and should just ask your isp to get you a static ip
Hey community! Iv been looking through docs but cannot find any specific examples thus far.
Has anyone used Python2 or Python3 to iterate through a subnet and list each individual subnet within that supernet? I.E pulling a list of /24's from 10.0.0.0/20.
TYIA!
first of all, don't use python2 unless you are on a system that doesn't support anything else
you are looking for the ipaddress modules which is part of the python standard library
import ipaddress
for subnet in ipaddress.ip_network('10.0.0.0/20').subnets(new_prefix=24):
print(subnet)
I have done it, thanks
Thankyou!! I will try that
I know, I was explaining the risk of port forwarding. The risk entirely depends on the process (app) you have running on the port, in of itself port forwarding is harmless
okay
Would this be a proper channel to ask for recourses on things like network automation and SDN
Hello I'm not entirely sure if this is the correct channel to post my question, please let me know if I should forward my question to another channel.
I'm currently developing on a Ubuntu 20.04 server which is connected to a proxy. I created a conda environment with python 3.8 and requests library so that I can consume an API.
The thing is that when I make an API call outside my virtual environment it works perfectly fine wget <api_endpoint>, but when I call the API using requests library within the conda environment it prompts me an error saying:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)
what do you mean "connected to a proxy"
Basically a gateway between the server in which I write my code and the Internet
could you explain... less basically? how can your entire server be "connected to a proxy"?
is it... a SOCKS proxy? an HTTP proxy? what?
HTTP proxy
and how is it connected to it?
Is it posible to figure out how is it connected cause I didn't set it up so I'm not entirely sure about how it's been set
there is generally no such thing as having a whole server connected to a proxy. individual connections can choose to go through a proxy
so you've probably misunderstood what's going on
Yeah probably
I feel like when I try to call the API within my conda environment the API server requires a certificate that I don't have stored
I feel like instead of getting the certificates from the OS it looks for certificates within /lib/site-packages/requests
And there is a certificate that is missing
what's the host?
Honestly I have no idea about how to solve it. I wonder if there is a way to tell requests library to look for OS certificates path instead of the ones that it has stored within the virtual environment or I should probably try to obtain the certificate from the API and paste the certificate into my virtual environment certificates path