zoukankan      html  css  js  c++  java
  • vb和php 基于socket通信

    php代码(页面代码非cmd命令脚本)

    <?php
    
    $server = '127.0.0.1';
    $port = 8888;
    
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if($socket < 0) {
        echo socket_strerror($socket);
    } else {
        echo '成功<br />';
    }
    
    
    $result = @socket_connect($socket, $server, $port);
    
    $buf = $_GET['message'];
    
    
    $len = strlen($buf);
    
    socket_send($socket, $buf, $len, 0);
    
    socket_close($socket);
    
    ?>

    vb代码

    Option Explicit
    
    
    Private Sub Form_Load()
        tcpServer.LocalPort = 8888
        tcpServer.Listen
        lblstate.Caption = "目前没有客户端连入!"
    End Sub
    
    Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
        If tcpServer.State <> sckClosed Then tcpServer.Close
        tcpServer.Accept requestID
        lblstate.Caption = "有客户端连入本机! IP:" & tcpServer.RemoteHostIP
    End Sub
    
    Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
        Dim strData As String
        tcpServer.GetData strData
        txtOutput.Text = strData & vbCrLf & txtOutput.Text
        tcpServer.Close
        tcpServer.Listen
    End Sub
    
    
    Private Sub txtSendData_KeyPress(KeyAscii As Integer)
        If KeyAscii = 13 Then
            If tcpServer.State = sckConnected Then
                tcpServer.SendData "服务器说:" & txtSendData.Text
                txtOutput.Text = "服务器说" & txtSendData.Text & vbCrLf & txtOutput.Text
                txtSendData.Text = ""
            Else
                MsgBox "目前没有连接的客户端!"
            End If
        End If
    End Sub

    效果

    http://bbs.csdn.net/topics/390614319

  • 相关阅读:
    PHP数组、函数
    PHP 基本内容
    Swift基础--tableview练习
    iOS 协议delegate分六步
    UI09_UITableView 使用 单例
    css清除浮动float的三种方法总结,为什么清浮动?浮动会有那些影响?一起来$('.float')
    CSS 如何使DIV层水平居中
    HTML转义字符大全
    jQuery选择器总结
    jQuery 学习笔记_01
  • 原文地址:https://www.cnblogs.com/hellowzd/p/5523361.html
Copyright © 2011-2022 走看看