/    Sign up×
Community /Pin to ProfileBookmark

I’d like to learn sockets..

eg.
comunicate with a server of tibia from a site.

I think i need to kno the following things to get a start..
How to send a socket, how to recieve a socket.

If someone has any good commented codes or would like to give me an explenation, id be verry gratefull.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 07.2005 — You can find a number of examples and quite a few user comments/examples starting here: http://www.php.net/manual/en/ref.sockets.php
Copy linkTweet thisAlerts:
@bokehNov 07.2005 — Also I would recommend testing on a local machine so you can intercept the data coming to and from the script. You will need a [URL=http://www.analogx.com/contents/download/network/pmon.htm]packet sniffer[/URL] for this.

The hardest part with sockets (in my opinion) is guessing what output you might receive from the remote server and then responding to that. [URL=http://bokehman.com/validate_email]Here is a script I wrote that uses sockets[/URL] which connects to mailservers and then displays the output.
Copy linkTweet thisAlerts:
@acemoauthorNov 07.2005 — There are already c++ coded servers made by looking at the packets that the client and official server uses, so i guess could ask one of the programmers of it, how it works for the chatting part.

Bokeh, i kno i need a packet sniffer for this and i already got one ? wpe pro 0.9a

I suppose u wont want to release the source of ur script? maybe only some small part of it?

nogdog, i dun really like the php.net site cuz mostly its like heaps of boring text and other pages often got lot less boring tutorials, was hoping u guys knew one for sockets, but ill read it trough ?

tnx
Copy linkTweet thisAlerts:
@bokehNov 07.2005 — Here's a piece of code (that actually works). This was the prototype but with the option to print debug output. It should give you an idea of socket communication in that one specific area.[code=php]function check_email_address_exists($email)
{
$print_debug = NULL; // set to TRUE to print output

if (!function_exists('getmxrr')){
require_once('getmxrr.php');
}
$result = true;

// Extract the mail server name from the email address.
list ($user, $domain) = split ("@", $email);
if (getmxrr($domain, $mxhost)){
$ConnectAddress = $mxhost[0];
}else{
$ConnectAddress = $domain;
}
if(gethostbynamel($ConnectAddress) === FALSE){
return FALSE;
}
// Try to open a socket at the mail server address.
if($ConnectAddress == $domain){
$connect = @fsockopen($ConnectAddress, 25, $errno, $errstr, 5);
}else{
$tries = count($mxhost);
$i = 0;
while(!$connect && !$tries == 0){
$connect = @fsockopen($mxhost[$i], 25, $errno, $errstr, 5);
$i++;
$tries--;
}
}

if ($connect)
{

if (ereg("^220", $out = fgets($connect, 1024)))
{
while(ereg('220', $out)){
$debug[] = 'Remote: '.$out;
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 10);
}
$debug[] = "Local: EHLO 13.red-80-37-41.staticip.rima-tde.net";
fputs ($connect, "EHLO 13.red-80-37-41.staticip.rima-tde.netrn");
$out = fgets ( $connect, 1024 );
while(!ereg('^250', $out)&&(!empty($out))){
$debug[] = 'Remote: '.$out;
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 10);
}
for($tries = 15; $tries > 0; $tries--){
if(ereg('^250', $out)){
$debug[] = 'Remote: '.$out;
$for_loop_hop = $out;
}elseif(empty($out)){
usleep(100000);
}else{
$debug[] = 'Remote: '.$out;
}
stream_set_timeout($connect, 0, 5000);
$out = fgets($connect, 1024);
stream_set_timeout($connect, 10);
}
if(!ereg('^250', $for_loop_hop)){
$debug[] = 'No 250';
if(isset($_GET['debug'])){
foreach($debug as $line){
echo $line.'<br>';
}
}
return FALSE;
}
$debug[] = htmlspecialchars("Local: MAIL FROM: <mailer_daemon@{$_SERVER['HTTP_HOST']}>rn");
fputs ($connect, "MAIL FROM: <{$email}>rn");
$from = fgets ( $connect, 1024 );
$debug[] = 'Remote: '.$from;
$debug[] = htmlspecialchars("Local: RCPT TO: <{$email}>rn");
fputs ($connect, "RCPT TO: <{$email}>rn");
$to = fgets ($connect, 1024);
$debug[] = 'Remote: '.$to;
$debug[] = "Local: QUITrn";
fputs ($connect, "QUITrn");
$quit = fgets ($connect, 1024);
$debug[] = 'Remote: '.$quit;
fclose($connect);

// Validate our exchange with the mail server.

// Server rejected address.
if (!ereg ("^250", $from) || !ereg ("^250", $to))
{
$result = false;
}
else
{
$result = 'Advice: Remote mail exchanger will accept mail for this address.';
}
}
// No response from server.
else
{
$i--;
$result = 'Advice: Remote mail exchanger '.$mxhost[$i].' faulty.';
}
}
// Can't connect to server.
else
{
$i--;
$result = 'Advice: Could not connect to remote mail exchanger: '.$mxhost[$i].'.';
}
if(isset($print_debug) and $print_debug){
if($debug > 0){
foreach($debug as $line){
print "$line <br />rn";
}
}
}
return $result;
}[/code]
×

Success!

Help @acemo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...