首页上一页 1 下一页尾页 1 条记录 1/1页
winsock控件广域网连接
发表在VB答疑区
2009-03-27
是否精华
是
否
版块置顶:
是
否
老师好:
我购买了VB技术开发大全,学习用winsock控件实现远程连接,在公司局域网内连接正常,在非局域网连接时却连不上。服务器IP为公司提供的公网固定IP,客户端使用GPRS无线网卡上网,连接之前从客户端ping 服务器IP确认是连通的,编写的代码如下:
客户端:
Private Sub Command1_Click()
Timer3.Enabled = True
Winsock1.RemoteHost = "218.104.109.29"
Winsock1.RemotePort = 2000
Winsock1.Connect
timer3.interval = 300
End Sub
Private Sub Timer3_Timer()
Dim st As String
If Winsock1.State <> 7 Then
b = MsgBox("没有连接,请查正后再试", vbInformation, "错误")
if b =1 then Exit Sub
Dim sts As String
Select Case Winsock1.State
Case 0
sts = "连接关闭"
Case 1
sts = "连接打开"
Case 2
sts = "监听"
Case 3
sts = "连接挂起"
Case 4
sts = "识别主机"
Case 5
sts = "已识别主机"
Case 6
sts = "正在连接"
Case 7
sts = "已连接"
Case 8
sts = "正在关闭连接"
Case 9
sts = "错误"
End Select
Form4.Label2 = sts
End Sub
Private Sub winsock1_close()
Timer1.Enabled = False
a = MsgBox("服务器关闭")
If a = 1 Then End
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DataStr As String
With Form4 '接收数据到文本框中
Winsock1.GetData DataStr
If .Text3.Text = "" Then
.Text3.Text = "从服务器端:" & DataStr
Else
.Text3.Text = .Text3.Text & vbCrLf & "从服务器端:" & DataStr
End If
End With
End Sub
服务器端:
Private Sub Form_Load()
flag = 2
Winsock1.LocalPort = 2000
Winsock1.Listen
End Sub
Private Sub winsock1_connectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
StrMsg = "已经建立连接!"
Winsock1.SendData StrMsg
Label1 = Winsock1.LocalIP
End Sub
另外:
光盘\mingrisoft\dxyy\25\01\01说明运行程序可以下载明日科技网站主页,运行程序后不见显示网页。
诚请指教,谢谢!
我购买了VB技术开发大全,学习用winsock控件实现远程连接,在公司局域网内连接正常,在非局域网连接时却连不上。服务器IP为公司提供的公网固定IP,客户端使用GPRS无线网卡上网,连接之前从客户端ping 服务器IP确认是连通的,编写的代码如下:
客户端:
Private Sub Command1_Click()
Timer3.Enabled = True
Winsock1.RemoteHost = "218.104.109.29"
Winsock1.RemotePort = 2000
Winsock1.Connect
timer3.interval = 300
End Sub
Private Sub Timer3_Timer()
Dim st As String
If Winsock1.State <> 7 Then
b = MsgBox("没有连接,请查正后再试", vbInformation, "错误")
if b =1 then Exit Sub
Dim sts As String
Select Case Winsock1.State
Case 0
sts = "连接关闭"
Case 1
sts = "连接打开"
Case 2
sts = "监听"
Case 3
sts = "连接挂起"
Case 4
sts = "识别主机"
Case 5
sts = "已识别主机"
Case 6
sts = "正在连接"
Case 7
sts = "已连接"
Case 8
sts = "正在关闭连接"
Case 9
sts = "错误"
End Select
Form4.Label2 = sts
End Sub
Private Sub winsock1_close()
Timer1.Enabled = False
a = MsgBox("服务器关闭")
If a = 1 Then End
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DataStr As String
With Form4 '接收数据到文本框中
Winsock1.GetData DataStr
If .Text3.Text = "" Then
.Text3.Text = "从服务器端:" & DataStr
Else
.Text3.Text = .Text3.Text & vbCrLf & "从服务器端:" & DataStr
End If
End With
End Sub
服务器端:
Private Sub Form_Load()
flag = 2
Winsock1.LocalPort = 2000
Winsock1.Listen
End Sub
Private Sub winsock1_connectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
StrMsg = "已经建立连接!"
Winsock1.SendData StrMsg
Label1 = Winsock1.LocalIP
End Sub
另外:
光盘\mingrisoft\dxyy\25\01\01说明运行程序可以下载明日科技网站主页,运行程序后不见显示网页。
诚请指教,谢谢!