Sponsored Content
Full Discussion: advanced socket programming
Top Forums Programming advanced socket programming Post 16066 by AtleRamsli on Monday 25th of February 2002 09:36:45 AM
Old 02-25-2002
In principle, all communication is 'binary'
That said, you have some options when creating a socket:

These are some protocols from a Linux book:
AF_UNIX (Is my book old, has this one gotten a new name?)
AF_INET - the one you probably want :-)
AF_ISO - Some new stuff ...
AF_NS - Xerox

Then, some socket types:

SOCK_STREAM - probably most used, connection based
SOCK_DGRAM - very intersting, can be fast on LAN
SOCK_RAW - Maybe this is the one you want?
If you build a new protocol, you may use this?

In principle, sockets are used like files:

open, read/write, close.

So, to transfer a file, you would open and write in one end, and open, read and close in the other ... but you probably have something particular in mind ...??

This is a GROSS oversimplification, does not speak about bind(), listen(), accept(), etc. - but check socket(3SOCKET), it will contain links to the other relevant calls.

Atle
 

10 More Discussions You Might Find Interesting

1. Programming

Socket Programming

Dear Reader, Is there any way to check up socket status other than 'netstatus ' Thanks in advance, (1 Reply)
Discussion started by: joseph_shibu
1 Replies

2. Programming

Socket Programming socket

Hello, I actually try to make client-server program. I'm using SCO OpenServer Release 5.0.0 and when I try to compile my code (by TELNET) I've got this error : I'm just using this simple code : and I get the same error if I use : If someone can help me, Thanks (2 Replies)
Discussion started by: soshell
2 Replies

3. IP Networking

socket programming

my system is a stand alone system... i want to try doing socket porgramming..ihave heard that this is usually done during testing... how can i do that....? (6 Replies)
Discussion started by: damn_bkb
6 Replies

4. Programming

Socket Programming

Hi , I'm facing the following problem in socket programming. My structure is struct { int i; char *str; }samp; I'm creating the pointer to this structure and assigning the value to the structure members and send via the socket to the another process. The receiver process when... (7 Replies)
Discussion started by: arunviswanath
7 Replies

5. Programming

help regarding socket programming

i m using sockets for setting up a connection between a server and a client. When the clients gets connected to the server, its ip is conveyed to the server through one of the predefined structures in c library... i save this ip address in an array....1st client's ip address goes to the zeroth... (1 Reply)
Discussion started by: abmxla007
1 Replies

6. UNIX for Dummies Questions & Answers

Socket programming

in c socket programming, how can I send and received on the same port? (7 Replies)
Discussion started by: Peevish
7 Replies

7. UNIX for Dummies Questions & Answers

hi i need help with socket programming

in socket programming how can i : Create for example 3 blank files, namely: server, client, network •Server: act as servers/provider, will receive all requests from different client •Client: requesters •Network: middle-layer of communication between server & client any tips or... (6 Replies)
Discussion started by: kedah160
6 Replies

8. Programming

Socket programming

Hi everyone, I'm new to this forum. I'm working on new project for last few days and this forum already helped me on couple of occasions. I don't have any prior experience with network programming so I'll appreciate any advise given. I'm trying to do the following: 1. open user... (2 Replies)
Discussion started by: _thomas
2 Replies

9. Homework & Coursework Questions

Trouble with Advanced Shell Programming

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am working on a hands on project. We are creating a script for a corporate phone list. The project I am... (2 Replies)
Discussion started by: SarahBelle7858
2 Replies

10. Ubuntu

Socket Programming

HI Can anyone provide me with codes for file transfer server to client or vice versa? Also please explain how to compile those programs in ubuntu terminal as i am totally new to socket programming. Thanks (1 Reply)
Discussion started by: mayhemtrigger
1 Replies
socket(3SOCKET) 					     Sockets Library Functions						   socket(3SOCKET)

NAME
socket - create an endpoint for communication SYNOPSIS
cc [ flag ... ] file ... -lsocket -lnsl [ library ... ] #include <sys/types.h> #include <sys/socket.h> int socket(int domain, int type, int protocol); DESCRIPTION
The socket() function creates an endpoint for communication and returns a descriptor. The domain argument specifies the protocol family within which communication takes place. The protocol family is generally the same as the address family for the addresses supplied in later operations on the socket. These families are defined in <sys/socket.h>. The currently supported protocol families are: PF_UNIX UNIX system internal protocols PF_INET Internet Protocol Version 4 (IPv4) PF_INET6 Internet Protocol Version 6 (IPv6) PF_NCA Network Cache and Accelerator (NCA) protocols The socket has the indicated type, which specifies the communication semantics. Currently defined types are: SOCK_STREAM SOCK_DGRAM SOCK_RAW SOCK_SEQPACKET SOCK_RDM There must be an entry in the netconfig(4) file for at least each protocol family and type required. If a non-zero protocol has been spec- ified but no exact match for the protocol family, type, and protocol is found, then the first entry containing the specified family and type with a protocol value of zero will be used. A SOCK_STREAM type provides sequenced, reliable, two-way connection-based byte streams. An out-of-band data transmission mechanism may be supported. A SOCK_DGRAM socket supports datagrams (connectionless, unreliable messages of a fixed (typically small) maximum length). A SOCK_SEQPACKET socket may provide a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer may be required to read an entire packet with each read system call. This facility is protocol specific, and presently not implemented for any protocol family. SOCK_RAW sockets provide access to internal network interfaces. The types SOCK_RAW, which is available only to a user with the net_rawaccess privilege, and SOCK_RDM, for which no implementation currently exists, are not described here. The protocol parameter is a protocol-family-specific value which specifies a particular protocol to be used with the socket. Normally this value is zero, as commonly only a single protocol exists to support a particular socket type within a given protocol family. However, mul- tiple protocols may exist, in which case a particular protocol may be specified in this manner. Sockets of type SOCK_STREAM are full-duplex byte streams, similar to pipes. A stream socket must be in a connected state before any data may be sent or received on it. A connection to another socket is created with a connect(3SOCKET) call. Once connected, data may be trans- ferred using read(2) and write(2) calls or some variant of the send(3SOCKET) and recv(3SOCKET) calls. When a session has been completed, a close(2) may be performed. Out-of-band data may also be transmitted as described on the send(3SOCKET) manual page and received as described on the recv(3SOCKET) manual page. The communications protocols used to implement a SOCK_STREAM insure that data is not lost or duplicated. If a piece of data for which the peer protocol has buffer space cannot be successfully transmitted within a reasonable length of time, then the connection is considered broken and calls will indicate an error with -1 returns and with ETIMEDOUT as the specific code in the global variable errno. The protocols optionally keep sockets "warm" by forcing transmissions roughly every minute in the absence of other activity. An error is then indicated if no response can be elicited on an otherwise idle connection for a extended period (for instance 5 minutes). A SIGPIPE signal is raised if a thread sends on a broken stream; this causes naive processes, which do not handle the signal, to exit. SOCK_SEQPACKET sockets employ the same system calls as SOCK_STREAM sockets. The only difference is that read(2) calls will return only the amount of data requested, and any remaining in the arriving packet will be discarded. SOCK_DGRAM and SOCK_RAW sockets allow datagrams to be sent to correspondents named in sendto(3SOCKET) calls. Datagrams are generally received with recvfrom(3SOCKET), which returns the next datagram with its return address. An fcntl(2) call can be used to specify a process group to receive a SIGURG signal when the out-of-band data arrives. It can also enable non-blocking I/O. The operation of sockets is controlled by socket level options. These options are defined in the file <sys/socket.h>. setsockopt(3SOCKET) and getsockopt(3SOCKET) are used to set and get options, respectively. RETURN VALUES
Upon successful completion, a descriptor referencing the socket is returned. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The socket() function will fail if: EACCES Permission to create a socket of the specified type or protocol is denied. EAGAIN There were insufficient resources available to complete the operation. EAFNOSUPPORT The specified address family is not supported by the protocol family. EMFILE The per-process descriptor table is full. ENOMEM Insufficient user memory is available. ENOSR There were insufficient STREAMS resources available to complete the operation. EPFNOSUPPORT The specified protocol family is not supported. EPROTONOSUPPORT The protocol type is not supported by the address family. EPROTOTYPE The socket type is not supported by the protocol. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
nca(1), close(2), fcntl(2), ioctl(2), read(2), write(2), accept(3SOCKET), bind(3SOCKET), connect(3SOCKET), getsockname(3SOCKET), getsock- opt(3SOCKET), in.h(3HEAD),listen(3SOCKET), recv(3SOCKET), setsockopt(3SOCKET), send(3SOCKET), shutdown(3SOCKET), socket.h(3HEAD), socket- pair(3SOCKET), attributes(5) NOTES
Historically, AF_* was commonly used in places where PF_* was meant. New code should be careful to use PF_* as necessary. SunOS 5.11 28 Jan 2009 socket(3SOCKET)
All times are GMT -4. The time now is 12:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy