作者a60301 (mt)
看板Visual_Basic
标题Re: [VB6 ] 关於WinSock IP的问题
时间Sun Aug 30 03:44:59 2009
怎麽没有人回答?
※ 引述《a60301 (mt)》之铭言:
: 我写了个程式
: 包含了Server端和Client端
: 程式码如下:
: [1;33;44mServer端程式[m
: Private Sub cls_Click()
: List1.Clear
: End Sub
: Private Sub sent_KeyPress(KeyAscii As Integer)
: If KeyAscii = 13 Then
: KeyAscii = 0
: If s.Enabled And sent.Text <> "" Then
: w1.SendData sent.Text
: a "Server说:" & sent.Text
: sent.Text = ""
: End If
: End If
: End Sub
: Private Sub startUp_Click()
: On Error GoTo er
: w1.Protocol = sckTCPProtocol
: w1.LocalPort = 8483
: w1.Listen
: a "启动Server On Port 8483"
: startUp.Enabled = False
: stopDown.Enabled = True
: Exit Sub
: er:
: a "Port 8483 已被其他程式使用中"
: End Sub
: Function a(ByVal str As String)
: List1.AddItem str
: List1.ListIndex = (List1.ListCount - 1)
: End Function
: Private Sub stopDown_Click()
: w1.Close
: a "关闭Server"
: startUp.Enabled = True
: stopDown.Enabled = False
: s.Enabled = False
: End Sub
: Private Sub w1_Close()
: a "连线已被关闭"
: stopDown_Click
: End Sub
: Private Sub w1_ConnectionRequest(ByVal requestID As Long)
: If w1.State <> sckClosed Then
: w1.Close
: w1.Accept requestID
: Else
: w1.Accept requestID
: End If
: a "Client连线成功"
: s.Enabled = True
: w1.SendData "CONNECT OK"
: End Sub
: Private Sub w1_DataArrival(ByVal bytesTotal As Long)
: Dim tmp As String
: w1.GetData tmp
: a "Client说:" & tmp
: End Sub
: [1;33;44mClient端程式[m
: Function a(ByVal str As String)
: List1.AddItem str
: List1.ListIndex = (List1.ListCount - 1)
: End Function
: Private Sub cls_Click()
: List1.Clear
: End Sub
: Private Sub Command2_Click()
: w1.Close
: Command1.Enabled = True
: Command2.Enabled = False
: s.Enabled = False
: a "连线已被关闭"
: End Sub
: Private Sub sent_KeyPress(KeyAscii As Integer)
: If KeyAscii = 13 Then
: KeyAscii = 0
: If s.Enabled And sent.Text <> "" Then
: w1.SendData sent.Text
: a "Client说:" & sent.Text
: sent.Text = ""
: End If
: End If
: End Sub
: Private Sub t_Timer()
: If t.Tag = "" Then
: a "无法连线"
: Command2_Click
: End If
: t.Enabled = False
: End Sub
: Private Sub w1_Close()
: a "Server已关闭"
: Command2_Click
: End Sub
: Private Sub w1_DataArrival(ByVal bytesTotal As Long)
: Dim srtData As String
: w1.GetData srtData
: If srtData = "CONNECT OK" Then
: t.Tag = "OK"
: a "连线成功"
: Else
: a "Server说:" & srtData
: End If
: End Sub
: Private Sub Command1_Click()
: host = InputBox("请输入 Server 的 IP")
: w1.RemoteHost = host
: w1.RemotePort = 8483
: w1.Connect
: Command1.Enabled = False
: Command2.Enabled = True
: s.Enabled = True
: a "连线至 " & host & ":8483 中..."
: t.Tag = ""
: t.Enabled = True
: End Sub
: 一切执行都很正常
: 问题出在於Server端
: 我想要有人在自己家里就可以开Server端
: 然後让Client端连近来
: 但是我试过了
: 除非设定路由器
: 或是直接由ADSL拨接
: 并取得实体IP
: 才可以连线
: 有没有什麽方法可以解决?
: 把WinSock换成别种方式吗?
: 还是改程式码就好了呢?
: 谢谢喔~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.167.21.169
1F:→ Yaiba:你知道127.0.0.1不能连...那怎麽会问私人IP要怎麽连的问题呢 09/03 01:13
我知道不行呀..是在想有什麽方法可以对连
※ 编辑: a60301 来自: 118.167.11.235 (09/09 11:08)