Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
将服务器IP修改成自动获取本机局域网IP
Browse files Browse the repository at this point in the history
  • Loading branch information
ICE99125 committed Nov 29, 2021
1 parent 24eb01c commit 834b023
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
16 changes: 16 additions & 0 deletions Func/get_ip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from socket import socket, AF_INET, SOCK_DGRAM


def getIPv4():
'''
获取本机 IPv4 地址
'''
try:
s = socket(AF_INET, SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
except Exception as e:
print(e)
finally:
s.close()
return ip
3 changes: 2 additions & 1 deletion Func/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from Func.board import Oneself_board, AI_board
from Func.client import Client
from Func.page_style import windowStyle
from Func.get_ip import getIPv4
import tkinter.ttk as ttk


Expand Down Expand Up @@ -110,7 +111,7 @@ def play_online(h):
h.destroy()

# 开启客户端
client = Client("10.22.164.18", 50007)
client = Client(getIPv4(), 50007)
client.invite_window(HOME)


Expand Down
8 changes: 2 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

4. 网络联机

> 需要运行 server.py
> 需要将 server.py 与 Func/page.py->play_online 里的 IP 改成自己的局域网
> 需要先运行 server.py
![image-20211120204526316](https://ice-berg.coding.net/p/Other/d/imgur/git/raw/master/2021/11/20/202111202045433.png)

Expand Down Expand Up @@ -79,7 +78,4 @@
2. [colingogogo/gobang_AI](https://github.com/colingogogo/gobang_AI.git)
2. [如何设计一个还可以的五子棋AI](https://kimlongli.github.io/2016/12/14/如何设计一个还可以的五子棋AI/)

> 除了 AI 有参考资料,其他的都太零碎了,面向百度编程,也没什么好引用的...


> 除了 AI 有参考资料,其他的都太零碎了,面向百度编程,也没什么好引用的...
3 changes: 2 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from threading import Thread
from time import strftime, localtime
from Func.json_byte import json_to_byte, byte_to_json
from Func.get_ip import getIPv4


# 服务器
Expand Down Expand Up @@ -169,5 +170,5 @@ def sendOnline(self):
conn.send(onlinePeople)


s = server("10.22.164.18", 50007)
s = server(getIPv4(), 50007)
s.start()

0 comments on commit 834b023

Please sign in to comment.