Be a Supporter!

Python socket explination

  • 357 Views
  • 5 Replies
New Topic Respond to this Topic
Turd-Of-The-Week
Turd-Of-The-Week
  • Member since: May. 25, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Python socket explination 2008-06-02 04:11:34 Reply

I can set up basic python sockets, however, I'm not sure how most of the functions in the socket module work, or how to use them correctly.


when in doubt.... punch HAMZ10 IN THE FUCKING FANNY!

BBS Signature
nns357
nns357
  • Member since: Jun. 2, 2008
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Python socket explination 2008-06-02 14:02:27 Reply

Thats like saying I put together an engine, yet I don't know how to put it in a car and get it to work... Or even worse. Maybe you should learn instead of thinking a tutorial, AKA copy and pasting, will teach you all you need to know.

VigilanteNighthawk
VigilanteNighthawk
  • Member since: Feb. 13, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Python socket explination 2008-06-02 22:02:46 Reply

I'm not very big into python, but here is the python reference on sockets: http://www.python.org/doc/lib/module-soc ket.html

I am somewhat familiar with socket programming from java, so if you have an architectural question, I may be able to give you a bit of guidance. I'll give a you a brief rundown of the basics:

tcp: transmission control protocol. Allows for long lasting connections between machines. Has error checking mechanism that keeps track to packets and the order in which they were sent. If packets were lost, they will be resent. Commonly used as the base protocol for data transmissions where data integrity is important such as FTP and HTTP.

udp: similar to tcp but lacks error checking mechanism. Because of this, lost packets are not resent. This protocol is unreliable where data integrity is key, but it because it lacks this error checking mechanism, it performs faster making it ideal for real time transmission such as game servers.

socket: used to connect to data source through a network (you knew this).
server socket: used to accept connections over a network. If I'm not mistaken, usually returns a regular socket for managing the connection (it has been a while.) Use this to accept connection from machines that don't have addresses you know in advance.

Nonblocking socket: Regular sockets are blocking. This means that your program will halt once it hits the socket and wait until it receives data before moving to the next portion. If used in a client, a blocking socket can hold up gui until data is received. If used in a server, the blocking socket will hold the progression of the server until the data transaction is completed. This means that if you have multiple connections, each connection will be processed one at a time. A non blocking socket will not have this effect. In java at least, if memory serves, the non blocking socket sets up an event queue to handle requests. If python does not have nonblocking sockets, you will have to use threads to handle socket transactions A thread allows you to run different parts of your program "at the same time."

At 6/2/08 02:02 PM, nns357 wrote: Thats like saying I put together an engine, yet I don't know how to put it in a car and get it to work... Or even worse. Maybe you should learn instead of thinking a tutorial, AKA copy and pasting, will teach you all you need to know.

Where did he ask for a tutorial? He may have used a tutorial to learn the basics and now needs a more complete picture. In fact, the OP came in here looking for more information so that he(she?) could gain a better understanding of sockets but is a bit lost currently. If the OP was simply a copy/paster, he'd go looking for the code online or ask us to write something or fix something from a tutorial. Sockets can be a bit confusing when you first encounter them.

Also, the only criticism I have against using tutorials is that they can be incomplete and are, in my opinion, more valuable to experienced programmers than to novices. I've learned a good deal from tutorials, and I've never copy and pasted. Again, I believe the OP is having trouble understanding what to do next but genuinely wants to learn. Your sanctimonious response provides no help and provides only undue criticism.


The Internet is like a screwdriver. You can use it to take an engine apart and understand it, or you can see how far you can stick it in your ear until you hit resistance.

Turd-Of-The-Week
Turd-Of-The-Week
  • Member since: May. 25, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Python socket explination 2008-06-03 01:04:11 Reply

I know how to create a basic setup...

I can use its basic functions such as "import socket, socket.socket(), mySock.bind(), socket.send, socket.listen" however there are tons of other functions I cannot use because I don't understand them...


when in doubt.... punch HAMZ10 IN THE FUCKING FANNY!

BBS Signature
VigilanteNighthawk
VigilanteNighthawk
  • Member since: Feb. 13, 2003
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Python socket explination 2008-06-03 01:08:17 Reply

Could you list specific functions that you are confused about or a problem you are trying to solve?


The Internet is like a screwdriver. You can use it to take an engine apart and understand it, or you can see how far you can stick it in your ear until you hit resistance.

Turd-Of-The-Week
Turd-Of-The-Week
  • Member since: May. 25, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to Python socket explination 2008-06-03 01:13:39 Reply

At 6/3/08 01:08 AM, VigilanteNighthawk wrote: Could you list specific functions that you are confused about or a problem you are trying to solve?

(protocol families)

AF_UNIX
AF_INET
AF_INET6

(protocols)

SOCK_STREAM
SOCK_DGRAM (datagram)
SOCK_RAW
SOCK_RDM
SOCK_SEQPACKET

and whatever the hell these are,

SO_*
SOMAXCONN
MSG_*
SOL_*
IPPROTO_*
IPPORT_*
INADDR_*
IP_*
IPV6_*
EAI_*
AI_*
NI_*
TCP_*

function:

has_ipv6 (checks for ipv6, and since I don't understand IPv6 (IP version 6?) I don't understand this)

socketpair([family[, type[, proto]]]) (Don't understand a socketpair)

getdefaulttimeout()

setdefaulttimeout()


when in doubt.... punch HAMZ10 IN THE FUCKING FANNY!

BBS Signature