![]() |
#2
lowxiong2013-01-05 20:20
|

Private Sub Form_Load()
Winsock1.LocalPort = 4858 '服务端 端口为 4858
Winsock1.Listen
local_port.Caption = Winsock1.LocalPort
gettext.Enabled = False
sendtext.Enabled = False
End Sub
Private Sub sendtext_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Winsock1.SendData sendtext.Text
sendtext.Text = ""
End If
End Sub
Private Sub Timer1_Timer()
winsock_state.Caption = Winsock1.State
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
MsgBox "No Client On Line !", vbInformation, "xyz"
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
MsgBox "Connect Success !", vbInformation, "xyz"
local_ip.Caption = Winsock1.LocalIP
client_ip.Caption = Winsock1.RemoteHostIP
Timer1.Enabled = True
gettext.Enabled = True
sendtext.Enabled = True
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim tmpstr As String
date_time = Date & " " & Time()
Winsock1.GetData tmpstr
gettext.Text = gettext.Text & date_time & vbCrLf & tmpstr & vbCrLf
End Sub '这是server

Private Sub Command1_Click()
Winsock1.RemoteHost = Text1.Text
Winsock1.Connect Winsock1.RemoteHost, Winsock1.RemotePort
local_ip.Caption = Winsock1.LocalIP
remote_port.Caption = Winsock1.RemotePort
sendtext.Enabled = True
gettext.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Form_Load()
gettext.Enabled = False
sendtext.Enabled = False
Winsock1.RemotePort = 4858
End Sub
Private Sub sendtext_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Winsock1.SendData sendtext.Text
sendtext.Text = ""
End If
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
MsgBox "Server Off Line !", vbInformation, "xyz"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim tmpstr As String
date_time = Date & " " & Time()
Winsock1.GetData tmpstr
gettext.Text = gettext.Text & date_time & vbCrLf & tmpstr & vbCrLf
End Sub '这是client
Winsock1.RemoteHost = Text1.Text
Winsock1.Connect Winsock1.RemoteHost, Winsock1.RemotePort
local_ip.Caption = Winsock1.LocalIP
remote_port.Caption = Winsock1.RemotePort
sendtext.Enabled = True
gettext.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Form_Load()
gettext.Enabled = False
sendtext.Enabled = False
Winsock1.RemotePort = 4858
End Sub
Private Sub sendtext_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Winsock1.SendData sendtext.Text
sendtext.Text = ""
End If
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
MsgBox "Server Off Line !", vbInformation, "xyz"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim tmpstr As String
date_time = Date & " " & Time()
Winsock1.GetData tmpstr
gettext.Text = gettext.Text & date_time & vbCrLf & tmpstr & vbCrLf
End Sub '这是client
把客户端发给别人,可是还不是能聊天..代码应该没问题呀,怎么解决下.刚接触winsock。。高手别喷