vb和php 基于socket通信
Posted 两只小蜜蜂啊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于vb和php 基于socket通信的主要内容,如果未能解决你的问题,请参考以下文章
linux网络编程之用socket实现简单客户端和服务端的通信(基于UDP)
Java TCP/IP Socket基于NIO的TCP通信(含代码)