Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83152 > unrolled thread
| Started by | pramod gowda <pramod.sp78@gmail.com> |
|---|---|
| First post | 2015-01-03 03:43 -0800 |
| Last post | 2015-01-04 18:12 +0000 |
| Articles | 11 — 6 participants |
Back to article view | Back to comp.lang.python
Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 03:43 -0800
Re: Socket programming Chris Angelico <rosuav@gmail.com> - 2015-01-03 22:56 +1100
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 04:25 -0800
Re: Socket programming Chris Angelico <rosuav@gmail.com> - 2015-01-03 23:38 +1100
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 05:22 -0800
Re: Socket programming mm0fmf <none@mailinator.com> - 2015-01-03 15:09 +0000
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 07:15 -0800
Re: Socket programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-04 02:57 +1100
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 08:10 -0800
Re: Socket programming Dan Stromberg <drsalists@gmail.com> - 2015-01-03 09:16 -0800
Re: Socket programming Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-01-04 18:12 +0000
| From | pramod gowda <pramod.sp78@gmail.com> |
|---|---|
| Date | 2015-01-03 03:43 -0800 |
| Subject | Socket programming |
| Message-ID | <f8631430-9364-42c8-8b12-daa3da4edf7c@googlegroups.com> |
Hi i am learning socket programming,
client code:
import socket
client_socket=socket.socket()
server_address='192.168.2.2'
server_port= 80
print("hello")
client_socket.connect((server_address,server_port))
print("hello")
data=client_socket.recv(1024)
print(data)
client_socket.close()
server code:
import socket
server_socket=socket.socket()
server_name='192.168.2.2'
server_port= 80
server_socket.bind((server_name,server_port))
server_socket.listen(1)
while True:
print("hello")
c,address=server_socket.accept()
print("we got connection from:",address)
c.send("hello,hw ru")
c.close()
I am not getting the output, i am using windows 7 OS..
please check and give me the solution.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-01-03 22:56 +1100 |
| Message-ID | <mailman.17347.1420286176.18130.python-list@python.org> |
| In reply to | #83152 |
On Sat, Jan 3, 2015 at 10:43 PM, pramod gowda <pramod.sp78@gmail.com> wrote: > I am not getting the output, i am using windows 7 OS.. > please check and give me the solution. Windows 7 - that's part of the story. What version of Python are you using? Is 192.168.2.2 the correct IP address? What happens when you run these? Do you get exceptions? ChrisA
[toc] | [prev] | [next] | [standalone]
| From | pramod gowda <pramod.sp78@gmail.com> |
|---|---|
| Date | 2015-01-03 04:25 -0800 |
| Message-ID | <3734210e-5811-4f05-b95d-ceb4c78c1377@googlegroups.com> |
| In reply to | #83154 |
On Saturday, January 3, 2015 5:26:27 PM UTC+5:30, Chris Angelico wrote: > On Sat, Jan 3, 2015 at 10:43 PM, pramod gowda <pramod.sp78@gmail.com> wrote: > > I am not getting the output, i am using windows 7 OS.. > > please check and give me the solution. > > Windows 7 - that's part of the story. What version of Python are you > using? Is 192.168.2.2 the correct IP address? What happens when you > run these? Do you get exceptions? > > ChrisA Hi chris. I am using python 3.4.2 I don get any exceptions, but wn i run the code,i don see any connections, IP address is given as my system IP. c,address=server_socket.accept() in server.py..if am trying to print something,it fails
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-01-03 23:38 +1100 |
| Message-ID | <mailman.17350.1420288695.18130.python-list@python.org> |
| In reply to | #83157 |
On Sat, Jan 3, 2015 at 11:25 PM, pramod gowda <pramod.sp78@gmail.com> wrote: > I am using python 3.4.2 > I don get any exceptions, > but wn i run the code,i don see any connections, IP address is given as my system IP. What does the client say? ChrisA
[toc] | [prev] | [next] | [standalone]
| From | pramod gowda <pramod.sp78@gmail.com> |
|---|---|
| Date | 2015-01-03 05:22 -0800 |
| Message-ID | <98b75dfe-0077-44b1-9b3d-fc242253b4ee@googlegroups.com> |
| In reply to | #83158 |
On Saturday, January 3, 2015 6:08:28 PM UTC+5:30, Chris Angelico wrote: > On Sat, Jan 3, 2015 at 11:25 PM, pramod gowda <pramod.sp78@gmail.com> wrote: > > I am using python 3.4.2 > > I don get any exceptions, > > but wn i run the code,i don see any connections, IP address is given as my system IP. > > What does the client say? > > ChrisA After c,address=server_socket.accept() ,this line of code,nothing s being executed. example i am just trying to print "Hello" thts also not being printed
[toc] | [prev] | [next] | [standalone]
| From | mm0fmf <none@mailinator.com> |
|---|---|
| Date | 2015-01-03 15:09 +0000 |
| Message-ID | <uCTpw.281005$P42.33854@fx24.am4> |
| In reply to | #83152 |
On 03/01/2015 11:43, pramod gowda wrote: > server_socket=socket.socket() > server_name='192.168.2.2' > server_port= 80 > server_socket.bind((server_name,server_port)) > server_socket.listen(1) I don't do much Python on Windows but do you have the necessary access rights to open a listening socket on port 80? Don't you need to run this with Administrator rights?
[toc] | [prev] | [next] | [standalone]
| From | pramod gowda <pramod.sp78@gmail.com> |
|---|---|
| Date | 2015-01-03 07:15 -0800 |
| Message-ID | <7a67b545-ee20-47c1-b8a9-fa83c4dfa660@googlegroups.com> |
| In reply to | #83163 |
On Saturday, January 3, 2015 8:39:26 PM UTC+5:30, mm0fmf wrote: > On 03/01/2015 11:43, pramod gowda wrote: > > server_socket=socket.socket() > > server_name='192.168.2.2' > > server_port= 80 > > server_socket.bind((server_name,server_port)) > > server_socket.listen(1) > > I don't do much Python on Windows but do you have the necessary access > rights to open a listening socket on port 80? Don't you need to run this > with Administrator rights? HI, i m doing n personal laptop. so i think i ve rights to open a listening socket,could u pls tell me hw can i check it?
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2015-01-04 02:57 +1100 |
| Message-ID | <54a81154$0$13000$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #83164 |
pramod gowda wrote: > HI, i m doing n personal laptop. > so i think i ve rights to open a listening socket,could u pls tell me hw > can i check it? Is your keyboard broken? There are a lot of missing characters in your sentences. You're going to have a lot of trouble programming with a broken keyboard. As far as sockets, this is a Python discussion group, not Windows experts. Try googling for more information and see if that helps: https://duckduckgo.com/?q=windows%20permission%20to%20open%20sockets -- Steven
[toc] | [prev] | [next] | [standalone]
| From | pramod gowda <pramod.sp78@gmail.com> |
|---|---|
| Date | 2015-01-03 08:10 -0800 |
| Message-ID | <c481f2b5-a6ac-4fa7-bf29-951a9f17984d@googlegroups.com> |
| In reply to | #83165 |
On Saturday, January 3, 2015 9:27:20 PM UTC+5:30, Steven D'Aprano wrote: > pramod gowda wrote: > > > HI, i m doing n personal laptop. > > so i think i ve rights to open a listening socket,could u pls tell me hw > > can i check it? > > Is your keyboard broken? There are a lot of missing characters in your > sentences. You're going to have a lot of trouble programming with a broken > keyboard. > > As far as sockets, this is a Python discussion group, not Windows experts. > Try googling for more information and see if that helps: > > https://duckduckgo.com/?q=windows%20permission%20to%20open%20sockets > > > > > -- > Steven Hi Steven, Sorry for using short words while posting,I am using python in windows7 with Python ver 3.4.2 for socket program,so i am asking for help. Thanks Pramod SP
[toc] | [prev] | [next] | [standalone]
| From | Dan Stromberg <drsalists@gmail.com> |
|---|---|
| Date | 2015-01-03 09:16 -0800 |
| Message-ID | <mailman.17352.1420305910.18130.python-list@python.org> |
| In reply to | #83152 |
On Sat, Jan 3, 2015 at 3:43 AM, pramod gowda <pramod.sp78@gmail.com> wrote:
> Hi i am learning socket programming,
This "works" on Linux Mint 17.1.
Server:
#!/usr/local/cpython-3.4/bin/python
import socket
server_socket = socket.socket()
#server_name = '192.168.2.2'
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_name = 'localhost'
server_port = 8080
server_socket.bind((server_name, server_port))
server_socket.listen(1)
while True:
print("hello")
c,address = server_socket.accept()
print("we got connection from:",address)
c.send(b"hello,hw ru")
c.close()
client:
#!/usr/local/cpython-3.4/bin/python
import socket
client_socket = socket.socket()
#server_address='192.168.2.2'
server_address = 'localhost'
server_port = 8080
print("hello")
client_socket.connect((server_address,server_port))
print("hello")
data=client_socket.recv(1024)
print(data)
client_socket.close()
But note that if you send 10 bytes into a socket, it could be received
as two chunks of 5, or other strangeness. So you should frame your
data somehow - adding crlf to the end of your send's is one simple
way. There are multiple ways of dealing with this. Here's one:
http://stromberg.dnsalias.org/~strombrg/bufsock.html with links to
others.
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2015-01-04 18:12 +0000 |
| Message-ID | <slrnmaj0kq.4et.grahn+nntp@frailea.sa.invalid> |
| In reply to | #83168 |
On Sat, 2015-01-03, Dan Stromberg wrote: > On Sat, Jan 3, 2015 at 3:43 AM, pramod gowda <pramod.sp78@gmail.com> wrote: ... > data=client_socket.recv(1024) > print(data) > client_socket.close() > > > But note that if you send 10 bytes into a socket, it could be received > as two chunks of 5, or other strangeness. So you should frame your > data somehow - adding crlf to the end of your send's is one simple > way. I like to think of it as "defining the protocol" rather than "framing your data". But it ends up as the same thing: making sure each end knows when it should stop looking for more data and start /acting/ on it. And yes, you can't do much with a TCP soocket without setting up these rules. It's important to see that noone does it /for/ you. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web