| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:socket通信
取消只看楼主 加入收藏
admin_xyz
Rank: 2
等 级:论坛游民
帖 子:195
专家分:77
注 册:2012-6-24
结帖率:97.3%
收藏
已结贴  问题点数:20 回复次数:1 
socket通信
程序代码:
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



把客户端发给别人,可是还不是能聊天..代码应该没问题呀,怎么解决下.刚接触winsock。。高手别喷
搜索更多相关主题的帖子: 通信 
2013-01-05 14:23
admin_xyz
Rank: 2
等 级:论坛游民
帖 子:195
专家分:77
注 册:2012-6-24
收藏
得分:0 
回复 2楼 lowxiong
求你了帮我看下,我都研究好几天了。。

总有人比你努力,可怕的是比你牛的人比你还努力。
2013-01-07 20:55
快速回复:socket通信
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039534 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved