[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Python Programming

You are currently reading a thread in /g/ - Technology

Thread replies: 7
Thread images: 2
File: osh shit waddup.jpg (76 KB, 500x733) Image search: [Google]
osh shit waddup.jpg
76 KB, 500x733
Hey guys I'm new to the /g/ board because I mostly use /b/ but I do enjoy doing amateur beginner programming. At the moment I'm trying to create a socket messenger in python. Do you guys think it's worth it to continue using python and also what could I do to improve it.

*Client:
import socket

TCP_IP = input("Server I.P? ")
TCP_PORT = int(input("Server Port? "))
NAME = input("Your alias? ")
BUFFER_SIZE = 1024

print("[+] Starting Client...")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("[+] Connecting To " + str(TCP_IP) + "...")
sock.connect((TCP_IP, TCP_PORT))
while True:
Message = input(NAME + "? ")
sock.send(("(n>)" + NAME + "(<n)" + Message).encode())
data = sock.recv(BUFFER_SIZE).decode()
Incoming = data[(data.index('(<n)') + 4)::]
Alias = data[4:(data.index('(<n)'))]
print(Alias + ": " + str(Incoming))

sock.close()

Server:
import socket

TCP_PORT = int(input("Server Port? "))
NAME = input("Your alias? ")
TCP_IP = 'I'm Not Retarded'
BUFFER_SIZE = 1024

print("[+] Starting Server...")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("[+] Binding The Port...")
s.bind((socket.gethostname(), TCP_PORT))
print("[+] Listening On Port...")
s.listen(5)

print("[+] Accepting Connections...")
conn, addr = s.accept()
print("Connection Address: " + str(addr))
while True:
data = conn.recv(BUFFER_SIZE).decode()
if not data: break
Incoming = data[((data).index('(<n)') + 4)::]
Alias = data[4:(data.index('(<n)'))]
print(Alias + ": " + Incoming)
Message = input(NAME + "? ")
conn.send(("(n>)" + NAME + "(<n)" + Message).encode())

conn.close()
>>
Python """"""""programming""""""""
>>
File: ramen.jpg (37 KB, 480x507) Image search: [Google]
ramen.jpg
37 KB, 480x507
>>54864058
Yeah I know I'm very beginner.
>>
>>54864082
That's some kind of rape, or at least sexual battery.
>>
>>54864031
Pastebin.
>>
>>54864031
please op tell me about dat boi
>>
OP you may want to go here instead: http://codereview.stackexchange.com/

Go ahead and continue using Python. You're just learning to program anyway, don't get caught up on whether a different language would be more efficient. Of course you should be doing it in Haskell but you might as well finish what you started! :-)
Thread replies: 7
Thread images: 2

[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK