Applications:
- server: streamserver
- client: streamclient
Application sources:
- server: /home/< user>/Desktop/socket_programming/server.c
- client: < home>/source/user/efe/streamclient
Building/running applications:
- server: gcc server.c –o streamserver
- client: refer to “Building an application”, “Installing an application” and “Running/testing an application” sections.
Description/synopsis
On a target (INCA-IP2 board) will be run the “streamclient” client application and on a host computer the “streamserver” server application.
“Streamclient” tries to establish stream socket (TCP) connection with “streamserver”, which runs on the host (whos IP address is 192.168.0.98) and listens to the port 3490. When “streamserver” detects incoming connection from the remote target, it sends “Hello world” text as response. “streamclient” will display on the standard output what it has received.
Preperation
1. Enabling port 3490 in firewall
Allow port 3490 by adding following lines (before COMMIT) to “/etc/sysconfig/iptables”:
# Allow port 3490 for an example application
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3490 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 3490 -j ACCEPT
# End of port 3490 rule
After that restart firewall with “service iptables restart” command.
2. Check if port 3490 opened
After loading “streamserver”, open another terminal window and invoke “netstat –na | grep 3490” to check if the port 3490 is open and listened. If the port is open, the command should return:
tcp 0 0 0.0.0.0:3490 0.0.0.0:* LISTEN
Testing example
First, start “streamserver” on the host computer:
server
When starts, it must display:
server: waiting for connections...
Then start “streamclient” on the target. For starting “streamclient”, an IP address of the host must be given as command line argument:
streamclient 192.168.0.98
When the client starts and receives data from the server, it must display:
client: connecting to 192.168.0.98
client: received 'He'
and the server must display:
server: got connection from 192.168.0.97
Then, terminate the server application with CTRL+C command on the host and start again client connection. This time the client must return:
client: connect: Connection refused
client: failed to connect
It means the socket on port 3490 is closed.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment