BalaMurugan Posted April 5, 2020 Share Posted April 5, 2020 (edited) This is my code to connect java socket:- ``` $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_connect($socket, '127.0.0.1', 12345); while(true) { // read a line from the socket $line = socket_read($socket, 1024, PHP_NORMAL_READ); var_dump($line); $someArray = json_decode($line, true); $otp = $someArray["otp"]; if($someArray["msg"] == "otp_generation") { $myObj = new \stdClass(); $myObj->msg = "OTP RECEIVED NEED TO CONNECT"; $send = json_encode($myObj); socket_send($socket, $send, strlen($send), 0); } exit; } ``` When connection is established successfully server send one OTP to client and received successfully in client. Then i send data to server OTP RECEIVED acknowledgement, it also received in server. After OTP RECEIVED acknowledgement server send welcome msg to client. I cant get the welcome message. if i remove the (exit) soket_write is not working i can't send data to server. if i put exit data send to server successfully and socket is closed. What can i do for this type of issue. I don't know what mistake i done.? Edited April 5, 2020 by BalaMurugan Add tags Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/ Share on other sites More sharing options...
requinix Posted April 5, 2020 Share Posted April 5, 2020 What documentation do you have for using the connection? Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/#findComment-1576369 Share on other sites More sharing options...
BalaMurugan Posted April 7, 2020 Author Share Posted April 7, 2020 On 4/5/2020 at 5:54 PM, requinix said: What documentation do you have for using the connection? I use php.net documentation an stackoverflow analyze. could u check what error i done? Please help to short this issue. Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/#findComment-1576477 Share on other sites More sharing options...
requinix Posted April 7, 2020 Share Posted April 7, 2020 Not PHP documentation. I mean what documentation for the Java socket itself do you have? Is there a specification for sending and receiving messages? Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/#findComment-1576478 Share on other sites More sharing options...
BalaMurugan Posted April 7, 2020 Author Share Posted April 7, 2020 (edited) 1 hour ago, requinix said: Not PHP documentation. I mean what documentation for the Java socket itself do you have? Is there a specification for sending and receiving messages? Yes Java Socket Itself. I just send and receive data using json. There is no rules for send and receive. I cant share my java server source code. So i create php socket server file for You. here is the code Link Server - https://pastebin.com/embed_iframe/L30uKQAr Client - https://pastebin.com/embed_iframe/Wfjzcebb Edited April 7, 2020 by BalaMurugan Attach source Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/#findComment-1576479 Share on other sites More sharing options...
BalaMurugan Posted April 7, 2020 Author Share Posted April 7, 2020 I don't have any documentation. I just use thread and java default socket. When socket connection timeout at the data is send. Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/#findComment-1576480 Share on other sites More sharing options...
requinix Posted April 8, 2020 Share Posted April 8, 2020 Okay, no documentation. What's the Java code on the other side of the socket? Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/#findComment-1576544 Share on other sites More sharing options...
BalaMurugan Posted April 8, 2020 Author Share Posted April 8, 2020 7 hours ago, requinix said: Okay, no documentation. What's the Java code on the other side of the socket? My Java socket is a big project. i can't share. i just create one php socket server for u. this is the link. I already share in comments, once again i ill share to you. Server - https://pastebin.com/embed_iframe/L30uKQAr Client - https://pastebin.com/embed_iframe/Wfjzcebb Quote Link to comment https://forums.phpfreaks.com/topic/310468-socket_send-not-working-without-break/#findComment-1576551 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.