Home > Software engineering >  VB and PHP SOCKET communication problems please help have a look
VB and PHP SOCKET communication problems please help have a look

Time:10-25



 & lt; ? PHP 

='127.0.0.1' $server;
$port=8888;

$sockets=socket_create (AF_INET SOCK_STREAM, SOL_TCP);
If ($socket & lt; 0 {
Echo socket_strerror ($socket);
} else {
Echo 'success & lt; Br/& gt; ';
}


$result=@ socket_connect ($sockets, $server, $port);

$buf='hello I'
$len=strlen ($buf);

Socket_send ($sockets, $buf, $len, 0).

Socket_close ($socket);

?>



 
Option Explicit


Private Sub Form_Load ()
TcpServer. LocalPort=8888
TcpServer. Listen
Lblstate. Caption="there is no client connected!"
End Sub

Private Sub tcpServer_ConnectionRequest (ByVal requestID As Long)
If tcpServer. State & lt;> SckClosed Then tcpServer. Close
TcpServer. Accept requestID
Lblstate. Caption="have the client connected to the machine! IP: "& amp; TcpServer. RemoteHostIP
End Sub

Private Sub tcpServer_DataArrival (ByVal bytesTotal As Long)
Dim strData As String
TcpServer. GetData strData
TxtOutput. Text=strData & amp; VbCrLf & amp; TxtOutput. Text
End Sub


Private Sub txtSendData_KeyPress (KeyAscii As Integer)
If KeyAscii=13 Then
If tcpServer. State=sckConnected Then
TcpServer. SendData publishes the event "server said:" & amp; TxtSendData. Text
Said txtOutput. Text="server" & amp; TxtSendData. Text & amp; VbCrLf & amp; TxtOutput. Text
TxtSendData. Text=""
The Else
MsgBox "there is no connection client!"
End the If
End the If
End Sub







normal but the second time for the first time when the refresh PHP page to the following error
 Warning: socket_send () function. The socket - send] : unable to write to the socket [0] : because the socket is not connected and (when using a sendto call send a datagram socket) does not provide the address, send or receive data request is not accepted, in E: \ \ wamp \ WWW \ test \ test3 PHP on line 19 


VB sometimes appear such mistakes

CodePudding user response:

Obviously, the service of your code can only support a client connection at once, so inevitable that as a result, suggest you still find another a Winsock multi-client communication examples and have a look, not a two words can explain clearly,

CodePudding user response:

I think, should be your PHP refreshed, it is the first connection is broken, to create a connection,
And your VB program there, only support a connection;
PHP to refresh the connection disconnected, your tcpServer doesn't disconnect (VB end should be not notified), so you can't accept the new connection request,

CodePudding user response:

refer to the second floor Chen8013 response:
, I think, should be your PHP refreshed, it is the first connection is broken, to create a connection,
And your VB program there, only support a connection;
PHP to refresh the connection disconnected, your tcpServer doesn't disconnect (VB end should be not notified), so you can't accept the new connection request,


 
Private Sub Form_Load ()
Winsock1. LocalPort=8888
Winsock1. Listen
End Sub

Private Sub winsock1_ConnectionRequest (ByVal requestID As Long)
If winsock1. State & lt;> SckClosed Then winsock1. Close
Winsock1. Accept requestID
Label1. Caption="have the client access to the machine! IP: "& amp; Winsock1. RemoteHostIP

End Sub

Private Sub winsock1_DataArrival (ByVal bytesTotal As Long)
Dim strData As String
Winsock1. GetData strData
Text1. Text=strData
Winsock1. Close
End Sub


I have added the close but it still won't do

CodePudding user response:

reference 1st floor CityBird response:
, obviously, you the server-side code can only support a client connection at once, so inevitable that as a result, suggest you still find another a Winsock multi-client communication examples and have a look, not a two words can explain,


refer to the second floor Chen8013 response:
, I think, should be your PHP refreshed, it is the first connection is broken, to create a connection,
And your VB program there, only support a connection;
PHP to refresh the connection disconnected, your tcpServer doesn't disconnect (VB end should be not notified), so you can't accept the new connection request,




My problem is resolved,


 in winsock1. Close added to listen to the following line 

Winsock1. Listen

CodePudding user response:

It seems I still guess the right reason,

CodePudding user response:

Although plus Winsock1. Listen to Listen, but still can only accept a client, if we open a new page as soon as the error!

CodePudding user response:

refer to 6th floor CityBird response:
although plus Winsock1. Listen to Listen, but still can only accept a client, if we open a new page as soon as the error!

His design, but can only accept a connection,
  • Related