jieweibin先生:
首先感谢您关注我的一个问题.我做了一个小的聊天服务器和客户端,在我的电脑上,两个程序能接通并对话,但是把客户端移么别的电脑上就不行了,您回答说可能是Mswinsck.ocx的协议有问题,我就把WindowsXP上的Mswinsck.ocx复制下来,可还是不灵,还出现同样的问题.您说的协议有问题,是不是指Mswinsck.ocx不是正版的?或者聊天程序里有关协议方面的语言有欠缺?想请您在百忙之中给我再详细解释一下,不胜感谢!
致礼!
天河水
2007年11月1日
首先感谢您关注我的一个问题.我做了一个小的聊天服务器和客户端,在我的电脑上,两个程序能接通并对话,但是把客户端移么别的电脑上就不行了,您回答说可能是Mswinsck.ocx的协议有问题,我就把WindowsXP上的Mswinsck.ocx复制下来,可还是不灵,还出现同样的问题.您说的协议有问题,是不是指Mswinsck.ocx不是正版的?或者聊天程序里有关协议方面的语言有欠缺?想请您在百忙之中给我再详细解释一下,不胜感谢!
致礼!
天河水
2007年11月1日
协议问题!
服务端IP设置问题!
差不多就这样了!
在本机是可以通讯的,那么,很有可能是你的端口和服务器IP设置问题了!
自己看看吧!
这个聊天程序是用VB编的.我现在把原码贴上来,请热心的朋友指点一下问题在哪.不胜感激.
以下是服务器代码:Winsck.ocx的protocol属性是0,即TCP协议.
Private Const wlocalport = 6898
Private Const maxs As Integer = 10
Private Sub statuschange()
Dim i As Integer
Dim actsession As Integer
For i = 1 To maxs
With Winsck(i)
If .State = 7 Then
actsession = actsession + 1
End If
End With
Next i
StatusBar1.Panels(1).Text = "会话数:" & Trim(str(actsession)) '在状态栏上显示会话数
End SubPrivate Sub Command1_Click()
receive.Clear
End SubPrivate Sub Command2_Click()
Dim i As Integer
For i = 1 To maxs
With Winsck(i)
If Winsck(i).State <> 0 Then
Winsck(i).SendData Text2.Text
End If
End With
Next i
Text2.Text = ""
End SubPrivate Sub Form_Load()
Dim i As Integer
With Winsck(0)
.Protocol = sckTCPProtocol
.LocalPort = wlocalport
.Listen
End With
For i = 1 To maxs
Load Winsck(i)
Winsck(i).Protocol = sckTCPProtocol
Winsck(i).LocalPort = wlocalport
Next i
Call statuschange
End SubPrivate Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)End SubPrivate Sub List1_Click()End SubPrivate Sub Winsock_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)End SubPrivate Sub Timer1_Timer()
statuschange
End SubPrivate Sub Winsck_Close(Index As Integer)
statuschange
End SubPrivate Sub Winsck_Connect(Index As Integer)
statuschange
End SubPrivate Sub Winsck_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim str As String
Dim i As Integer
If Index = 0 Then
For i = 1 To maxs
With Winsck(i)
If .State = 0 Then
.Accept requestID
.SendData "恭喜你,已经接通了!"
Exit For
End If
End With
Next i
End IfEnd SubPrivate Sub Winsck_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim str As String
Dim i As Integer
Winsck(Index).GetData str, , bytesTotal
receive.AddItem str
For i = 1 To maxs
With Winsck(i)
If .State = 7 Then
.SendData Text1.Text
DoEvents
End If
End With
Next i
End Sub
以下是客户端代码:Winsck.ocx的protocol属性设置也是0
Private Sub Command1_Click()
If Winclient.State = 0 Then
Winclient.Connect
End If
End SubPrivate Sub Command2_Click()
If Winclient.State <> 0 Then
Winclient.SendData Text1.Text
Else
MsgBox "请先打开连接!"
End If
Text1.Text = ""
End SubPrivate Sub Command3_Click()
Text1.Text = ""
List1.Clear
End SubPrivate Sub Form_Load()
Winclient.Protocol = sckTCPProtocol
Winclient.RemoteHost = "192.168.1.88"
Winclient.RemotePort = 6898
End SubPrivate Sub Winclient_DataArrival(ByVal bytesTotal As Long)
Dim dr As String
Winclient.GetData dr, , bytesTotal
List1.AddItem dr
End Sub
再次感谢大家.谢谢!