Sponsored Content
Full Discussion: Sockets!?!?!?!?!?!
Top Forums Programming Sockets!?!?!?!?!?! Post 39307 by cbkihong on Tuesday 12th of August 2003 10:39:30 PM
Old 08-12-2003
That guide is somewhat recommended by many college courses on Unix network programming. That's why I gave you this link.

1. Really? When I read it some time ago I didn't recall I saw this problem. Perhaps a few places may be. I may help clarify if you give me exactly where the omissions go. By the way, they're functions, not methods. When you talked about methods I did take some time wondering what you meant.

2. listen() lasts until you teardown the socket.

The chapter describing the functions do not have full examples. On the next chapter (Client-Server Background) you'll find examples in full that you can try on your system.

3. Assuming you're using TCP (not datagrams). Once a server accept() a connection, from the accept(2) manpage, "it creates a new connected socket with mostly the same properties as s, and allocates a new file descriptor for the socket, which is returned." You can then use recv() on this returned socket (not the one which you called listen() on!) to receive data. You'll need to allocate a buffer, and very likely you should put it in a loop to get the incoming data in chunks. Somewhere in the document it mentioned encapsulating your data by putting a header indicating the length of data. You can use this scheme to decide whether you would like to make a dynamic buffer which fits all the data, for instance so you don't need multiple recvs.

4. Theoretically you can, by using a cross-compiler, then one can compile a Unix C program on Windows or vice versa. I don't have any experience on gcc cross-compilers though, so you may need a search on google for this.
 

10 More Discussions You Might Find Interesting

1. Programming

sockets...

Hi ! I had a verry simple question to ask... In unix when we create pipes.. the unnamed pipes that is... is there any way to access those pipes outside the code ? Another thing.. do sockets have an entry in the inode table ? TIA, Devyani. (1 Reply)
Discussion started by: devy8
1 Replies

2. Programming

sockets

Hai, How cani declare socket and collect the data in a string varialbe. Since i am new to this i am asking this. Can we connect multiple port. Thank you. (6 Replies)
Discussion started by: arunkumar_mca
6 Replies

3. UNIX for Dummies Questions & Answers

sockets

how do i mointor how many sockets are opened from a particular foriegn address? (2 Replies)
Discussion started by: kirpond
2 Replies

4. Solaris

Sockets in use

Is there a way to see what sockets are in use? The developers here are getting some defunct processes and they would like to get a socket list. This is on a Solaris 8 machine. Thanks! (1 Reply)
Discussion started by: kjbaumann
1 Replies

5. IP Networking

sockets and firewall

Is it possible to trace the packages and the statuses of client's and/or server's sockets by the UNIX network administrative tools? Two applications interact via sockets. There is no problem if they stay in the same network segment. If their hosts connected through the firewall then they aren't... (4 Replies)
Discussion started by: gogogo
4 Replies

6. Programming

need help with sockets

anyone and teach me how to save standard output to a file in a client/server socket. I know how to read them to the screen but i'm not quite sure how to save them to a file. my read to screen file code: memset(line, 0x0, LINE_ARRAY_SIZE); while (recv(connectSocket, line, MAX_MSG, 0) >... (1 Reply)
Discussion started by: crunchyuser
1 Replies

7. Programming

Sockets

Hi,i now moved into a different section where i need to use sockets. i am completely nill in sockets. can some body please provide me what are the requirements for a socket. to use sockets in c. thanks (1 Reply)
Discussion started by: MrUser
1 Replies

8. Programming

Help with sockets in C

if i have a server which wants to connect to exactly 5 clients, does that mean i need 5 socket file descriptors and use listen(socket_fd,1); for each one or just do listen(socket_fd,5) also whats the second parameter number mean? what happens if i put 0 there? also if i am connected... (28 Replies)
Discussion started by: omega666
28 Replies

9. Red Hat

Sockets

hai guys, I'm doing a project in which one server communicates with several clients. How can i do it when i have different port numbers???:confused: (0 Replies)
Discussion started by: rajeshb6
0 Replies

10. Programming

Any example about sockets in C++?

Hi, i am student, think learning about c++, someone has a example the how establish a conection with sockets :b::b: (1 Reply)
Discussion started by: mmartinez
1 Replies
LISTEN(2)						      BSD System Calls Manual							 LISTEN(2)

NAME
listen -- listen for connections on a socket LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> int listen(int s, int backlog); DESCRIPTION
To accept connections, a socket is first created with socket(2), a willingness to accept incoming connections and a queue limit for incoming connections are specified with listen(), and then the connections are accepted with accept(2). The listen() system call applies only to sockets of type SOCK_STREAM or SOCK_SEQPACKET. The backlog argument defines the maximum length the queue of pending connections may grow to. The real maximum queue length will be 1.5 times more than the value specified in the backlog argument. A subsequent listen() system call on the listening socket allows the caller to change the maximum queue length using a new backlog argument. If a connection request arrives with the queue full the client may receive an error with an indication of ECONNREFUSED, or, in the case of TCP, the connection will be silently dropped. Current queue lengths of listening sockets can be queried using netstat(1) command. Note that before FreeBSD 4.5 and the introduction of the syncache, the backlog argument also determined the length of the incomplete connec- tion queue, which held TCP sockets in the process of completing TCP's 3-way handshake. These incomplete connections are now held entirely in the syncache, which is unaffected by queue lengths. Inflated backlog values to help handle denial of service attacks are no longer neces- sary. The sysctl(3) MIB variable kern.ipc.soacceptqueue specifies a hard limit on backlog; if a value greater than kern.ipc.soacceptqueue or less than zero is specified, backlog is silently forced to kern.ipc.soacceptqueue. INTERACTION WITH ACCEPT FILTERS
When accept filtering is used on a socket, a second queue will be used to hold sockets that have connected, but have not yet met their accept filtering criteria. Once the criteria has been met, these sockets will be moved over into the completed connection queue to be accept(2)ed. If this secondary queue is full and a new connection comes in, the oldest socket which has not yet met its accept filter criteria will be terminated. This secondary queue, like the primary listen queue, is sized according to the backlog argument. RETURN VALUES
The listen() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The listen() system call will fail if: [EBADF] The argument s is not a valid descriptor. [EDESTADDRREQ] The socket is not bound to a local address, and the protocol does not support listening on an unbound socket. [EINVAL] The socket is already connected, or in the process of being connected. [ENOTSOCK] The argument s is not a socket. [EOPNOTSUPP] The socket is not of a type that supports the operation listen(). SEE ALSO
netstat(1), accept(2), connect(2), socket(2), sysctl(3), sysctl(8), accept_filter(9) HISTORY
The listen() system call appeared in 4.2BSD. The ability to configure the maximum backlog at run-time, and to use a negative backlog to request the maximum allowable value, was introduced in FreeBSD 2.2. The kern.ipc.somaxconn sysctl(3) has been replaced with kern.ipc.soacceptqueue in FreeBSD 10.0 to prevent confusion about its actual functionality. The original sysctl(3) kern.ipc.somaxconn is still available but hidden from a sysctl(3) -a output so that existing applications and scripts continue to work. BSD
July 15, 2014 BSD
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy