在已联网的计算机上创建TCP / IP连接 [英] Creating a TCP/IP connection on already-networked computers

查看:81
本文介绍了在已联网的计算机上创建TCP / IP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我看看这个问题是否有意义......我正在阅读Core Python

编程我跳到了更具体的主题,如网络

节目。我打算按照该章中的示例进行操作。

在我的桌面和笔记本电脑之间创建套接字连接。


但是,这两台计算机已经连接在我的家庭网络上

(使用Windows网络安装向导),所以我想知道这个

是否会影响我可能尝试用Python做什么。在其他

字样中,如果我编写的程序实际工作并允许两台

计算机相互通话,那将是纯粹的结果

计划,或者它与家庭网络上已经存在的事实有什么关系? (即还有另一个变量?)

谢谢。

Let me see if this question even makes sense...I''m reading Core Python
Programming and I jumped ahead to the more specific topics like network
programming. I plan to follow along with the example in that chapter and
create a socket connection between my desktop and laptop.

However, these two computers are already connected on my home network
(using the Windows Network Setup Wizard), so I was wondering if this
will have any effect on what I might try to do with Python. In other
words, if the program I write actually works and allows the two
computers to speak to each other, will that be a result purely of the
program, or will it have anything to do with the fact that they are
already on a home network together? (i.e. there''s another variable in play?)

Thanks.

推荐答案

2008- 06-14,John Salerno< jo ****** @gmailNOSPAM.comwrote:
On 2008-06-14, John Salerno <jo******@gmailNOSPAM.comwrote:

让我看看这个问题是否有意义......我正在阅读

核心Python编程和我跳到更多

特定主题,如网络编程。我计划跟随

以及该章中的示例,并在我的桌面和笔记本电脑之间创建一个插座

连接。


但是,这两台计算机已经连接在我家的网络上(使用Windows网络安装向导),所以我想知道这是否对我有什么影响可能会尝试用Python做

Let me see if this question even makes sense...I''m reading
Core Python Programming and I jumped ahead to the more
specific topics like network programming. I plan to follow
along with the example in that chapter and create a socket
connection between my desktop and laptop.

However, these two computers are already connected on my home
network (using the Windows Network Setup Wizard), so I was
wondering if this will have any effect on what I might try to
do with Python.



我不知道你正在谈论的示例程序,但

这是一个相当不错的选择如果两台计算机无法使用IP网络相互联系,示例程序将无法正常工作。

I don''t know the example programs you''re talking about, but
it''s a pretty good bet that the example programs won''t work if
the two computers can''t reach each other using IP networking.


换句话说,如果我编写的程序实际工作并且

允许两台计算机相互通话,那将是纯粹的程序结果,还是它有任何关系

因为他们已经在家庭网络上了

在一起? (即播放中还有另一个变量?)
In other words, if the program I write actually works and
allows the two computers to speak to each other, will that be
a result purely of the program, or will it have anything to do
with the fact that they are already on a home network
together? (i.e. there''s another variable in play?)



两个Python程序无法与每个进行通信

除非两台计算机已经设置在网络上,否则允许在两台计算机之间路由IP数据包。

我认为这是什么网络设置向导做了(设置IP

网络),但我不是真的做窗户(我特别不要这样做,但是如果我可以避免的话,那就是巫师) )。


-

格兰特爱德华兹格兰特哇!好吧,你!!

模拟一个伤口密封

visi.com恳求停车

空间!!

The two Python programs won''t be able to communicate with each
other unless the two computers are already set up on network(s)
that allow the routing of IP packets between the two computers.
I presume that''s what the "Network Setup Wizard" did (set up IP
networking), but I don''t really do windows (I especially don''t
do "Wizards" if I can avoid it).

--
Grant Edwards grante Yow! Alright, you!!
at Imitate a WOUNDED SEAL
visi.com pleading for a PARKING
SPACE!!


John Salerno写道:
John Salerno wrote:

如果我编写的程序实际工作并允许两台

计算机彼此说话,这纯粹是

计划的结果,还是与家庭网络上已经存在的事实有关? ?
if the program I write actually works and allows the two
computers to speak to each other, will that be a result purely of the
program, or will it have anything to do with the fact that they are
already on a home network together?



这是两个程序。先服务器,然后是客户端。他们的工作,这b / b $ b本身让我感到惊讶,创建一个网络连接就这么简单
这样的
!但我的基本问题是:如果两台计算机(每台运行其中一个脚本)完全相互无关,那么这个连接是否会起作用?我的两个人在家庭网络上,但是如果我要运行服务器程序并且有一个我的朋友(谁住在某个地方

)运行客户端程序,它还能用吗?


-----

#!/ usr / bin / env python


来自套接字导入*

来自时间导入ctime


HOST =''192.168.1.100''

PORT = 21567

BUFSIZ = 1024

ADDR =(主机,端口)

tcpSerSock = socket(AF_INET,SOCK_STREAM)

tcpSerSock.bind(ADDR)

tcpSerSock.listen(5)

而True:

打印''等待for connection ...''

tcpCliSock,addr = tcpSerSock.accept()

print''... from from:'',addr


而True:

data = tcpCliSock.recv(BUFSIZ)

如果不是数据:

break

tcpCliSock.send(''[%s]%s''%(ctime(),data))

tcpCliSock.close()


t cpSerSock.close()

-----


-----

#!/ usr / bin / env python


来自套接字导入*


HOST ='''192.168.1.100''

PORT = 21567

BUFSIZ = 1024

ADDR =(主机,端口)

tcpCliSock = socket(AF_INET,SOCK_STREAM)

tcpCliSock.connect(ADDR)

而True:

data = raw_input('''')

如果不是数据:

休息

tcpCliSock.send(数据)

data = tcpCliSock.recv(BUFSIZ)

如果没有数据:

破解

打印数据


tcpCliSock.close()

- ----

Here are the two programs. Server first, then client. They work, which
in itself amazes me that it''s so simple to create a network connection
like this! But my basic question is this: would this connection work if
the two computers (each running one of these scripts) were completely
unrelated to one another? My two are on a home network, but if I were to
run the server program and have a friend of mine (who lives somewhere
else) run the client program, would it still work?

-----
#!/usr/bin/env python

from socket import *
from time import ctime

HOST = ''192.168.1.100''
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)

tcpSerSock = socket(AF_INET, SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)

while True:
print ''waiting for connection...''
tcpCliSock, addr = tcpSerSock.accept()
print ''...connected from:'', addr

while True:
data = tcpCliSock.recv(BUFSIZ)
if not data:
break
tcpCliSock.send(''[%s] %s'' % (ctime(), data))

tcpCliSock.close()

tcpSerSock.close()
-----

-----
#!/usr/bin/env python

from socket import *

HOST = ''192.168.1.100''
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)

tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)

while True:
data = raw_input('''')
if not data:
break
tcpCliSock.send(data)
data = tcpCliSock.recv(BUFSIZ)
if not data:
break
print data

tcpCliSock.close()
-----


John Salerno写道:
John Salerno wrote:

-----

#!/ usr / bin / env python


来自时间导入ctime


HOST ='''192.168.1.100''
-----
#!/usr/bin/env python

from socket import *
from time import ctime

HOST = ''192.168.1.100''


-----

#!/ usr / bin / env python
来自套接字导入的
*


HOST ='''192.168.1.100' '
-----
#!/usr/bin/env python

from socket import *

HOST = ''192.168.1.100''



关于此问题。是主机吗?在这两种情况下都指的是

服务器计算机的IP地址?因为当我运行程序时,

并且到达了连接起来:的部分。在服务器端,

它显示相同的IP地址。不应该是不同的东西,

因为请求来自与服务器不同的计算机

计算机?

A question about this. Is the "HOST" referring to the IP address of the
server computer in both of these cases? Because when I ran the program
and got to the part where it says "connected from:" on the server side,
it shows this same IP address. Shouldn''t it be something different,
since the requests are coming from a different computer than the server
computer?

这篇关于在已联网的计算机上创建TCP / IP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆