[Tutor] Socket Programming issue

aditya nauty.me04 at gmail.com
Tue Jun 21 09:37:28 CEST 2011


On Tue, Jun 21, 2011 at 12:45 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "aditya" <nauty.me04 at gmail.com> wrote
>
>
>  is that although the Vbscript writes the output to the file correctly but
>> when the client sends the contents of the file to the server via socket ,
>> it
>> sometimes prints all the lines of the file on the server and sometimes it
>> doesnt , i dont know whether the issue is with the client or the server ,
>>
>
> Use the return values from functions.
>
>
>  CLIENT.PY
>>
>> import socket
>> import os
>> import sys
>> os.system("C:\Python26\ping.**vbs")
>> host = "localhost"
>> port= 23333
>> size = 1024
>>
>> s=socket.socket(socket.AF_**INET, socket.SOCK_STREAM)
>> s.connect((host,port))
>>
>> f=open('output.txt','r')
>> while 1:
>> data = f.readline()
>>
>
> You could print the data here to check that you got something
> meaningful from the file....
>
>
>  if data: s.send(data)
>>
>
> The socket documentation specifically says:
> ------------------------------**---
> socket.send(string[, flags])
>  Send data to the socket. The socket must be connected to a remote socket.
> The optional flags argument has the same meaning as for recv() above.
> Returns the number of bytes sent. Applications are responsible for checking
> that all data has been sent; if only some of the data was transmitted, the
> application needs to attempt delivery of the remaining data.
>
> >Thanks Alan i will put in some conditional checks to check and reattempt
to send the data if it has not been sent or not. besides i am sending you
the client,server, and the output file to just go though it once . You can
run the script for yourself and see what happens.It actually prints only one
line of the ouput file and some times all the lines at the server end.

Besides can you help me with the checks which you insist me to put in
socket.send() ?







> ------------------------------**------------
> Notice that it tells you how many bytes have been sent, and it
> is your responsibility to check and retry if necessary.
> I see no check nor any attempt to retry....
>
> That should tell you if the data is leaving the client at least.
>
>
>
>  SERVER.PY
>> import socket
>>
>> host = ""
>> port = 23333
>> size = 1024
>> backlog=5
>> s=socket.socket(socket.AF_**INET, socket.SOCK_STREAM)
>>
>> s.bind((host,port))
>> s.listen(backlog)
>>
>> while 1:
>> client, addr =s.accept()
>> data=client.recv(size)
>> if data:
>> print data
>> else:
>> print  "client exit"
>>
>
> This implies you should always get something printed, do you?
> When you say it sometimes prints the lines and sometimes
> not, does it print the exit message instead?
>
>  s.close()
>>
>
> I'm not clear where this line sits since the mail has lost
> its indentation. Is it inside the else or at the while level?
>
> Just some things to c0onsider,
>
> HTH
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Regards
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110621/e0741ed7/attachment.html>
-------------- next part --------------
reply from 192.168.100.1
reply from 192.168.100.7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: client.py
Type: application/octet-stream
Size: 346 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20110621/e0741ed7/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: server.py
Type: application/octet-stream
Size: 304 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20110621/e0741ed7/attachment-0001.obj>


More information about the Tutor mailing list