Sponsored Content
Full Discussion: Read and write to tcp socket
Top Forums Shell Programming and Scripting Read and write to tcp socket Post 302660839 by cfajohnson on Saturday 23rd of June 2012 12:19:07 PM
Old 06-23-2012
Code:
#!/bin/bash

usage="${0##*/} SERVER USER PASSWORD [PORT]"

case $1 in
    -*|"") printf "USAGE: %s\n" "$usage"; exit ;;
esac

host=${1:-mail.example.com}
user=${2:-poppy}
passwd=${3:-pop3test}
port=${4:-110}

CR=$'\r'                            ## carriage return; for removal of
exec 3<>/dev/tcp/$host/$port        ## connect to POP3 server, port 110
read ok line <&3                    ## get response from server
[ "${ok%$CR}" != "+OK" ] && exit 5  ## check that it succeeded
echo user "$user" >&3               ## send user name
read ok line <&3                    ## get response
[ "${ok%$CR}" != "+OK" ] && exit 5  ## check that it succeeded
echo pass "$passwd" >&3             ## send password
read ok line <&3                    ## get response
[ "${ok%$CR}" != "+OK" ] && exit 5  ## check that it succeeded
echo stat >&3                       ## request number of messages
read ok num x <&3                   ## get response
echo Messages: $num                 ## display number of messages
echo quit >&3                       ## close connection

These 2 Users Gave Thanks to cfajohnson For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

Confusion about TCP/IP socket programming

Hello there chaps. First of all, i'm no TCP/IP-wiz, so forgive me if this is a stupid question. I've been messing around with filetransfer using sockets, and there is one thing that confuses me. This is how it's set up: A server app listens on a port for a client connection. When it... (3 Replies)
Discussion started by: crippe
3 Replies

2. UNIX for Dummies Questions & Answers

Which application has a TCP socket open

If I do a netstat -a I can see all the sockets currently open, is there a way that I can tell which application is holding open these sockets ? (3 Replies)
Discussion started by: murphyboy
3 Replies

3. Programming

read/write socket error

I have client and server connected. client write and read from csock. server write and read from ssock suppose the server does : .... close(ssock); //send FIN to client othertask(); .... READ ERROR if after the server close() the client does: ... read(csock,...); ...... (2 Replies)
Discussion started by: gio
2 Replies

4. AIX

TCP/IP socket binding problem

I have what appears to be a unique socket problem, although admittedly my tcp/ip programming experience is relatively limited. I have a AIX server process using TCP/IP berkely sockets, and a Windows (C#) process. The windows process takes input from a user and sends a message to the Unix... (1 Reply)
Discussion started by: adiaconou
1 Replies

5. Programming

problem receiving data from TCP socket

Hi all, I'm writing a socket program which sends a structure from one machine to another. When I run my client first time it runs well, however after the first time I couldn't receive all the data inside the structure (it is like, half of the array is received and the other half is not set). I... (1 Reply)
Discussion started by: SaTYR
1 Replies

6. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

7. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

8. Programming

Need help about read() and write() on TCP/IP

HI I need to implement a client/server TCP application. the customer is the client and the bartender is the server. When the customer enter the Bar, client connects to the server Server should reply the client immediately. Other wise if the server is busy, it should send an update message... (10 Replies)
Discussion started by: lixiao1212
10 Replies

9. Programming

Using socket to test a TCP port

Hello, I'm trying to write a small c application to test a tcp port. This works fine for the most part but the default timeout on the connect is very long. I have been reading many posts but and it looks like I need to set the socket to be non-blocking and poll for a result. I have been totally... (2 Replies)
Discussion started by: tjones1105
2 Replies

10. IP Networking

Packets sent from Linux TCP socket

Hello, Our software is using a TCP socket (AF_INET, SOCK_STREAM) to communicate with an Ethernet device. When we send a message, the message object writes itself in full onto the socket's stream buffer before the software invokes send() from socket.h. I'm still researching, but have 2... (1 Reply)
Discussion started by: bix_20002000
1 Replies
JSONBOT(1)							    jsb manual								JSONBOT(1)

NAME
jsb-sleek - The JSONBOT Sleek (XMPP) program SYNOPSIS
JSONBOT is a remote event-driven framework for building bots that talk JSON to each other over XMPP. jsb-sleek is the shell XMPP program using the SleekXMPP library. see http://sleekxmpp.com DESCRIPTION
jsb-sleek can connect to xmpp servers, join a conference and react on /msg. USAGE
Usage: jsb-sleek [options] Options: --version show program's version number and exit -h, --help show this help message and exit -r PATH resume the bot from the folder specified -d DATADIR, --datadir=DATADIR datadir of the bot -u USER, --user=USER JID of the bot -o OWNER, --owner=OWNER owner of the bot -s SERVER, --server=SERVER server to connect to (irc) -c CHANNEL, --channel=CHANNEL channel to join -l LOGLEVEL, --loglevel=LOGLEVEL loglevel of the bot -p PASSWORD, --password=PASSWORD set password used to connect to the server --name=NAME bot's name --port=PORT set port of server to connect to --save save to config file -n NICK, --nick=NICK nick of the bot DOCUMENTATION
See http://jsonbot.org or http://jsonbot.appspot.com/docs for more documentation SEE ALSO
jsb(1), jsb-backup(1), jsb-init(1), jsb-irc(1), jsb-fleet(1), jsb-stop(1), jsb-udp(1), jsb-xmpp(1) AUTHOR
This manual page was written by Bart Thate <bthate@gmail.com>, for the Debian GNU/Linux system (but may be used by others). Debian GNU/Linux 22 Nov 2011 JSONBOT(1)
All times are GMT -4. The time now is 04:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy