<?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 = '你好啊我';$len = strlen($buf);socket_send($socket, $buf, $len, 0);socket_close($socket);?>
Option ExplicitPrivate Sub Form_Load() tcpServer.LocalPort = 8888 tcpServer.Listen lblstate.Caption = "目前没有客户端连入!"End SubPrivate Sub tcpServer_ConnectionRequest(ByVal requestID As Long) If tcpServer.State <> sckClosed Then tcpServer.Close tcpServer.Accept requestID lblstate.Caption = "有客户端连入本机! IP:" & tcpServer.RemoteHostIPEnd SubPrivate Sub tcpServer_DataArrival(ByVal bytesTotal As Long) Dim strData As String tcpServer.GetData strData txtOutput.Text = strData & vbCrLf & txtOutput.TextEnd SubPrivate 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 IfEnd Sub
第一次正常 但是 第二次刷新 PHP页面的时候出现 如下错误
Warning: socket_send() [function.socket-send]: unable to write to socket [0]: 由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。 in E:\wamp\www\test\test3.php on line 19
回复讨论(解决方案)
把 @socket_connect 取消@看看是否有警告信息
把 @socket_connect 取消@看看是否有警告信息
Warning: socket_connect() [function.socket-connect]: unable to connect [0]: 由于目标计算机积极拒绝,无法连接。 in E:\wamp\www\test\test3.php on line 14Warning: socket_send() [function.socket-send]: unable to write to socket [0]: 由于套接字没有连接并且(当使用一个 sendto 调用发送数据报套接字时)没有提供地址,发送或接收数据的请求没有被接受。 in E:\wamp\www\test\test3.php on line 19
估计是已经连接过一次了
Y
VB那边应该有关闭连接的动作,不懂VB,你自己看看
VB那边的问题。他只接受一个连接。
VB那边的问题。他只接受一个连接。
我用VB 和 VB 时间通信 连接一次就可以了
但是为什么用PHP 和 VB 通信 为什么会增多连接? 不能原连接基础上 继续发送数据吗
VB->VB creat, connect只有一次
PHP 每刷新就creat一次,所以是很多个连接
VB->VB creat, connect只有一次
PHP 每刷新就creat一次,所以是很多个连接
唉不知道这个问题如何解决
我只是想做个功能 PHP 发送后 VB 的客户端方面接收数据 并把数据保存到 TXT 中
其他都很简单 就这个连接麻烦 解决不了
刷新页面不行吧,你刷新一次等一服务器重新执行一次,应该是在后台保持长连接的
VB->VB creat, connect只有一次
PHP 每刷新就creat一次,所以是很多个连接
唉不知道这个问题如何解决
我只是想做个功能 PHP 发送后 VB 的客户端方面接收数据 并把数据保存到 TXT 中
其他都很简单 就这个连接麻烦 解决不了
这是你的设计架构。你要解决的现实问题是什么?聊天?办公?
VB->VB creat, connect只有一次
PHP 每刷新就creat一次,所以是很多个连接
唉不知道这个问题如何解决
我只是想做个功能 PHP 发送后 VB 的客户端方面接收数据 并把数据保存到 TXT 中
其他都很简单 就这个连接麻烦 解决不了
VB接收完就close连接
VB->VB creat, connect只有一次
PHP 每刷新就creat一次,所以是很多个连接
唉不知道这个问题如何解决
我只是想做个功能 PHP 发送后 VB 的客户端方面接收数据 并把数据保存到 TXT 中
其他都很简单 就这个连接麻烦 解决不了
VB接收完就close连接
Private Sub Form_Load() winsock1.LocalPort = 8888 winsock1.ListenEnd SubPrivate Sub winsock1_ConnectionRequest(ByVal requestID As Long) If winsock1.State <> sckClosed Then winsock1.Close winsock1.Accept requestID Label1.Caption = "有客户端接入本机!IP:为" & winsock1.RemoteHostIPEnd SubPrivate Sub winsock1_DataArrival(ByVal bytesTotal As Long) Dim strData As String winsock1.GetData strData Text1.Text = strData winsock1.CloseEnd Sub
我已经增加了 但是还是不行
你自己看看VB书吧,感觉你是把整个socket都close了,应该只是关闭连接
socket关闭了,就是连bind/accept都废了
你自己看看VB书吧,感觉你是把整个socket都close了,应该只是关闭连接
socket关闭了,就是连bind/accept都废了
今天也在找相关书籍 但是一直没找到 唉
你自己看看VB书吧,感觉你是把整个socket都close了,应该只是关闭连接
socket关闭了,就是连bind/accept都废了
我的问题解决了
在 winsock1.Close 下面加了 重新监听 就行了winsock1.Listen

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
