Will yea, TCP vs UDP is speed/size witch comes down to how the 2 dos packet management, UDP sends stuff and doesnt care if it gets there or not. While TCP waits and resends if it doesnt. Why I think TCP should be used for logons and other important data, UDP can be used to send key commands that needs to go to the server perty fast. (aka moving around or jumping)
I have not done alot of testing of the both (cus I dont have 2 PC to test on fully, cus they are lan connections) so i’m not 100% sure UDP is that bad compare to TCP in having packets in the wrong order or missing.
Edit: Haha my idea was sorta right, after some seraching on the web I came by this "Unfortunately there is no mitigation for the reliability of TCP. If a packet is dropped, then no new packets will be accepted until the missing packet arrives. This can cause a great amount of perceived lag. Have you ever played a game where you are moving your sprite, and then all of a sudden you stop moving, so you keep hitting the forward button. Then, all of the sudden your sprite bursts into a fast-forward sprint. This is because the movement packets were sent with TCP. "
This is how my current code look/works (it doesnt have what you showed me yet) It was only setup for 1 user. Haha and you can see why when you look at someone else network code its alot bigger then whats really there=)
#Server program
from socket import *
import threading
import time
# Set the socket parameters
host = ""
port = 21568
port2 = 21567
buf = 1024
buf2 = 1024
addr = (host,port)
# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
data,addr = UDPSock.recvfrom(buf)
client = data
addr2 = (client, port2)
data,addr = UDPSock.recvfrom(buf)
if data == "Hey you there?":
data = "Yes"
(UDPSock.sendto(data,addr2))
print client, " trying to log on."
else:
print "unknow error 200"
data,addr = UDPSock.recvfrom(buf)
name = data
data2 = "Users/" + name + ".txt"
f = open(data2,"r")
lineList = f.readlines()
f.close()
name2 = "Name: " + name + "\n"
if name2 == lineList[0]:
data,addr = UDPSock.recvfrom(buf)
password = "Password: " + data + "\n"
if password == lineList[1]:
print name,"log on."
data = lineList[2].strip()
(UDPSock.sendto(data,addr2))
data = lineList[3].strip()
(UDPSock.sendto(data,addr2))
data = "===Welcome==="
(UDPSock.sendto(data,addr2))
while 1:
data,addr = UDPSock.recvfrom(buf)
f = open("myfile.txt", 'r+')
for l in f:
l + "\n"
msg = "received: " + time.ctime() + ": " + data + "\n"
f.write(msg)
f.close()
print "\nReceived message '", msg,"'"
else:
print "Wrong."
else:
print "No one by that name."
# Close socket
UDPSock.close()