![Epson C32C824461 - UB R03 Print Server Скачать руководство пользователя страница 75](http://html.mh-extra.com/html/epson/c32c824461-ub-r03-print-server/c32c824461-ub-r03-print-server_technical-reference-manual_108346075.webp)
Chapter 4 Programming
75
4
For Linux
The
program
is
a
sample
of
printing
ʺ
EPSON
UB
‐
R03
ʺ
to
a
TM
printer
with
the
UB
‐
R03
from
the
Windows
shell,
through
the
Ethernet
connection.
------------------------------------------------------------------------------------------------------------------
/* TCP9100 programming sample for linux
* HOW TO BUILD
* cc tcp9100.c
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
int main(int argc, char* argv[])
{
int sockfd;
struct sockaddr_in addr;
if (argc != 2) {
printf("usage: tcp9100 IP_ADDRESS\n");
exit(1);
}
/* create socket */
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
perror("socket()");
exit(1);
}
/* initialize the parameter */
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(9100);
addr.sin_addr.s_addr = inet_addr(argv[1]);
/* connect */
if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
perror("connect()");
}
printf("connected\n");
/* send data */
send(sockfd, "EPSON UB-R03\x0a", 13, 0);
/* close socket */
close(sockfd);
return 0;
}
------------------------------------------------------------------------------------------------------------------