Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 20th, 2004, 10:40 PM
Noah_C Noah_C is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 34 Noah_C User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 31 sec
Reputation Power: 5
Sockets ?

I've read online both in ebooks and tutorials on how sockets work. All of which give a different example on how to get this set up. I've searched this forum as well, but can anyone provide an example of code that just sets up a socket and the client sends text and then ends the connects with the server socket.


Thanks!

Reply With Quote
  #2  
Old June 20th, 2004, 11:39 PM
NetBSD NetBSD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Canada
Posts: 234 NetBSD Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 9 h 25 m 35 sec
Reputation Power: 0
Send a message via MSN to NetBSD
Quick example (no error checking):

Code:
import socket

mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect((127.0.0.1, 50007))
mysock.send("Hello, World!")
mysock.close()


Look here for more info: http://docs.python.org/lib/module-socket.html

Reply With Quote
  #3  
Old June 21st, 2004, 12:13 AM
Noah_C Noah_C is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 34 Noah_C User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 31 sec
Reputation Power: 5
Can you maybe provide a server example as well ?

Thanks for the sample code as well, it's much appreciated.

Reply With Quote
  #4  
Old June 21st, 2004, 10:01 AM
NetBSD NetBSD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Canada
Posts: 234 NetBSD Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 9 h 25 m 35 sec
Reputation Power: 0
Send a message via MSN to NetBSD
Code:
import

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 50007))
server.listen(1024)

(client, addr) = server.accept()
print "Connection: ", addr[0]

input = client.recv(1024)
print "Received: ", input

client.close()
server.close()


It shouldn't be too hard to expand on these to make them interactive if you so desire.

EDIT: There are some good protocol dependent and indepentent examples here: http://docs.python.org/lib/socket-example.html

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Sockets ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT