LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2005, 09:11 AM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
Converting php5 socket functions to php3 socket functions


I have the following socket functions coded in php5. I need to convert them to php3 which I am assuming is dealing with the fsockopen function. I am new to php coding and was wondering if anyone can help me with this task. Basically I need to go right down the line and get the equivalent function for socket create, socket_bind, socket_listen, socket_accept, socket_read. Can anyone help me with this?

Code:
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
		echo "socket_create() failed. Reason: " . socket_strerror($sock) . "<BR>";
	}

	if (($ret = socket_bind($sock, $address, $port)) < 0) {
		echo "socket_bind() failed. Reason: " . socket_strerror($ret) . "<BR>";
	}

	//Start listening on the socket
	if (($ret = socket_listen($sock, 5)) < 0) {
		echo "socket_listen() failed. Reason: " . socket_strerror($ret) . "<BR>";
	}

	//Accept an incoming connection
	if(($client = socket_accept($sock)) < 0) {
		echo "socket_accept() failed. Reason: " . socket_strerror($ret) . "<BR>";
		break;
	}

	//Read whatever was just sent, 1024 bytes' worth. Make this however long you need.
	if( false == ($global_string = socket_read($client, 2048))) {
		echo "socket_read() failed. Reason: " . socket_strerror($ret) . "<BR>";
		break;
	}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP5-MySQL Not Connecting Through Socket oxblood Linux - Software 5 03-15-2010 05:53 PM
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 01:58 PM
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 07:28 PM
Passing Functions through Socket sunny_krishna Linux - Software 1 04-15-2004 08:20 AM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration