From: "Dmitry V. Levin" <ldv@altlinux.org>
To: ALT Linux general discussion list <community@altlinux.ru>
Subject: Re: [Comm] Q: Programming sockets in C language troubles
Date: Mon, 19 May 2003 16:14:22 +0400
Message-ID: <20030519121422.GA3240@basalt.office.altlinux.org> (raw)
In-Reply-To: <20030519113800.GA18016@abr.tool.ru>
[-- Attachment #1: Type: text/plain, Size: 2288 bytes --]
On Mon, May 19, 2003 at 03:38:00PM +0400, Andrey Brindeew wrote:
> На работе встала задача перегонять данные с одной машины (расчетная,
> сервер) на другую (отображение) по сети. В качестве языка используется
> Си, ОС Linux, поэтому было решено использовать сокеты для передачи, дабы
> ничего не изобретать ("всё уже украдено до нас" (C) :-) )
>
> Берем тривиальный пример из документации по glibc (pinfo select, самая
> последняя ссылка на странице: Server Example). Чуть-чуть дорабатываем
> (избавляемся от функции make_socket путем включения ее в программу) и
> пытаемся тестить:
>
> $ gcc -o srv{,.c}
> $ ./srv
>
> На другой консоли:
> $ telnet 127.0.0.1 1200
> Trying 127.0.0.1...
> Connected to 127.0.0.1.
> Escape character is '^]'.
> protocol_command 12345
$ apropos telnet netcat
telnet (1) - user interface to the TELNET protocol
netcat (1) - arbitrary TCP and UDP connections and listens
> Переключаемся на серверную консоль: _тишина полная_.
> Нажимаем Enter три (или больше) раз - видим следующее:
>
> $ ./srv
>
> got message from 0 client: `
> ╛@пВЪ©PВЪ©└'
Это telnet protocol, RFC 854.
[...]
> Теперь вопросы:
> 1. Почему у нас на серверной консоли фигурируют 0, 1 и 2 сокеты (я
> так понимаю, что это stdin, stdout и stderr сервера собственной
> персоной)? Я их в FD_SET не заказывал на прослушивание с помощью
> select. :-(
А кто будет FD_ISSET делать?
> 2. Что за мусор идет после подстроки "protocol_com"? Я так понимаю, что
> буфер чтения у сокета заполнился (ибо 12 символов всего), но откуда
> мусор?
Это telnet protocol, RFC 854.
> 3. Почему сообщение о подсоединении клиента не появилось сразу же после
> того, как я подцепился к серверу с помощью telnet?
Это telnet protocol, RFC 854.
> 4. Я наверное еще много чего не понимаю, какая хорошая литература есть
> в сети и код какой _хорошо написанной_ программы можно посмотреть
> для примера? В исходниках sshd и popa3d запутался... :-(
Stevens W.R. UNIX Network Programming, Volume 1, Second Edition,
Networking APIs: Sockets and XTI // Prentice Hall, Upper Saddle River,
N.J., 1998
Есть (в Москве наверняка) перевод на русский язык, но имейте в виду, что,
в отличие от перевода второго тома, перевод этого тома содержит тьму
ошибок.
--
ldv
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
prev parent reply other threads:[~2003-05-19 12:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-19 11:38 Andrey Brindeew
2003-05-19 11:48 ` Sergey Bolshakov
2003-05-19 11:55 ` Sergey Bolshakov
2003-05-19 12:05 ` Sergey Vlasov
2003-05-23 11:28 ` [Comm] " Andrey Brindeew
2003-05-19 12:14 ` Dmitry V. Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030519121422.GA3240@basalt.office.altlinux.org \
--to=ldv@altlinux.org \
--cc=community@altlinux.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git