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

  • 相关阅读:
    Python Module_subprocess_子进程(程序调用)
    开机自启动Powershell脚本
    开机自启动Powershell脚本
    Powershell 音乐播放
    Powershell 音乐播放
    Powershell指令集_2
    Zabbix实战-简易教程(1)--总流程
    AWS上获取监控数据(EC2/RDS都支持)
    Grafana最新版本4.3.1安装(后端使用mysql)
    Haproxy实战(3)
  • 原文地址:https://www.cnblogs.com/hellowzd/p/5523361.html
Copyright © 2011-2022 走看看