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

  • 相关阅读:
    Javascript 组成:ECMAscript、Dom、Bom
    js字符串的操作
    函数(方法)基本内容
    for循环运用,三角形
    Java Script 数组
    控制语句—for循环、while循环
    JavaScript基础内容
    网站创建中遇到的问题
    数据库无法启动ORA-01034: ORACLE not available
    关于数据库管理员安全和权限
  • 原文地址:https://www.cnblogs.com/hellowzd/p/5523361.html
Copyright © 2011-2022 走看看