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""""""""
>>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! :-)