![]() |
help with sockets, having a client recieve data as well as send.
i have a semi-complex socket program that I just wrote ( first foray into sockets in python ) but for the purposes of figuring this out, I'll use a much simpler example.
:
#client.pyin these examples, client.py sends data to server.py. Its my understanding that server.py checks for incoming data because it has binded itself to the specified address. Beyond that, the two sockets seem identical. So, i wrote a method that has server.py use the same send command that client does to send a message to the client. this didnt work. I thought it was because I hadn't bound client to an address, so I did. However, i bound it to the same address as the server, so I changed the port (because theyre both running on the same computer). This didnt work, the program crashed, and good old python doesnt stay on to show you the run time errors, it just turns itself off. Can anyone modify the above example so that both can act as client/servers on the same computer? Thanks. |
The server is just the program that has bound itself to a port and will handle any data that is sent to that port. The client doesn't need to bind itself to anything, it just sends and receives data from the socket it's connected on. The simple socket example shows the client sending and receiving data from the server.
|
thanks for that clarification and the example : )
|
question: my example was of UDP sockets, ures is TCP. it seems TCP can't handle multiple clients on one port while UDP can. is there anyway to make change either so they can have both up and down communication as well multiple clients. or am i mistaken, and what you gave me is just the new way of doing what i was (ie, my way is deprecated). thanks...
edit: just to be concise, forget all i said about differences and what not, simply, is there any way for more than one client to connect to that particular server, cuz it seems that its only listening to one particular port and address ( one client ) at a time. thanks. final edit ( and i shall leave you alone ) : is it possible to sort of wait for unique connections and keep them in a list, and later loop thru each waiting for incoming data making sure to keep them distinct. i'll try this but im not sure how to implement it. alternatively, i can have one thread in the server wait for incoming connections, and then maintain seperate threads for each client. it only occured to me now that the blasted accept() method waits till something actually connects. thats so odd, what if i dont know how many clients i'm expecting. |
ok i think ive almost figured it out. thanks for your help man. im just gunna use a lot of threads, i hope python and my processor can handle it. not sure if there are smarter solutions. thanks. now how do i close a thread..?
|
Quote:
Quote:
Quote:
This is precisely what happens when you call serversocket.listen(int). In between each call to serveroscket.accept(), it will keep that many connections waiting in line to be processed. Quote:
:
while True:Quote:
As for stopping a thread, a thread automagically stops when the run() function stops, so you can easily do something like the following: :
class MyThread(threading.Thread):Hope that makes sense. Ask if you need any clarification. |
lol, i meant, how do i close a topic thread on this forum. thanks for ure help, i made a very hot solution ( im proud of it ) and im turning this cool pygame game into an online thing now. thanks.
|
That's great to hear :-)
As for closing a thread, don't bother. You may just want to put (solved) in the title or something of the sort. |
| All times are GMT -5. The time now is 6:14 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC