if the python code works, in theory it works with django, I suggest you try
to run it first and asking questions if it doesn't


On Mon, May 27, 2013 at 3:22 PM, <[email protected]> wrote:

> Can you kindly advice me if this are the right steps to do to create an
> application that handle a TCP/IP connection as client to a server and show
> sended and received data in a webpage?
>
> 1) model: define fields to be shown in the web-page
> 2) view: handle socket connection
>              send data function
>              receive data function
>
> This is the python code that I've been using to connect to server, I can
> use it in django?
>
> Please let me know, thanks
>
>
> #Socket client
> import socket   #for sockets
> import sys  #for exit
> #create an INET, STREAMing socket
> try:
>     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> except socket.error:
>     print 'Failed to create socket'
>     sys.exit()
> print 'Socket Created'
> host = '192.168.1.1';
> port = 35000;
> try:
>     remote_ip = socket.gethostbyname( host )
> except socket.gaierror:
>     #could not resolve
>     print 'Hostname could not be resolved. Exiting'
>     sys.exit()
> #Connect to remote server
> s.connect((remote_ip , port))
> print 'Socket Connected to ' + host + ' on ip ' + remote_ip
> #Send some data to remote server
> message = "GET / HTTP/1.1\r\n\r\n"
> try :
>     #Set the whole string
>     s.sendall(message)
> except socket.error:
>     #Send failed
>     print 'Send failed'
>     sys.exit()
> print 'Message send successfully'
> #Now receive data
> reply = s.recv(4096)
> print reply
>
> s.close()
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to