Sponsored Content
Top Forums Shell Programming and Scripting simple socket programming in perl Post 302228165 by redoubtable on Saturday 23rd of August 2008 06:43:30 AM
Old 08-23-2008
Under Linux there is a way to make any file handler / file descriptor non-block through the fcntl() function.

Code:
use POSIX;
...
fcntl($MySocket, F_SETFL(), O_NONBLOCK()); # call this before $MySocket->recv($text,128)
...

You can also use sysread() which won't block.
 

10 More Discussions You Might Find Interesting

1. Programming

Socket programming

Suppose i am writing a C program which is going to use Socket calls. I want to use a Unix port for my Socket. How can i determine a port which is not already in use? (1 Reply)
Discussion started by: Nadeem Mistry
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. Programming

Need Help Regarding Socket Programming

Can anyone plz me. I need a sample code for the following description. Its urgent. It is C/Socket program with the following descriptions: NAME coreadServer - Concurrent Readers Server. coreadClient - Concurrent Readers Client. SYNOPSIS coreadServer <OutputFile> coreadClient <n>... (1 Reply)
Discussion started by: priya.vmr
1 Replies

4. 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

5. UNIX for Advanced & Expert Users

socket programming

Hi, I am trying to connect to more than 60 servers to perform some actions remotely. for this I am using ssh2. But its taking lot of time. Though i am running the command in background, still its taking long time to execute.. Any one let me know can we use sockets instead of ssh2 for... (3 Replies)
Discussion started by: pvamsikr
3 Replies

6. Programming

Help with socket programming in C

hi guys i got this code trying to make connection between the server and multi clients but when i do ./server i got message server waiting then when i run ./client it says client 1 nosuch file i dont know whats that should i use any argument plz help how to compile and run and whats the expected... (1 Reply)
Discussion started by: kedah160
1 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

help with socket programming in c

i'm doing a simple program in socket programming on c i have server that can handle 2clients in a single machine i'm running ubuntu linux so i got it work but the probelm when clients send a message the server will echo it but i cant distinguish which client send the message client 1 or client... (7 Replies)
Discussion started by: kedah160
7 Replies

9. Programming

socket programming

how to include socket.h in visual studio 2005.. (2 Replies)
Discussion started by: asd123
2 Replies

10. Shell Programming and Scripting

Socket Programming in Perl

Hi All I am getting an error when using the below code Receiver use IO::Socket; $sock = new IO::Socket::INET (LocalHost => 'goldengate', LocalPort => 1200, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Socket could not be created. Reason: $!" unless $sock; while ($new_sock =... (5 Replies)
Discussion started by: parthmittal2007
5 Replies
FCNTL(2)							System Calls Manual							  FCNTL(2)

NAME
fcntl - file control SYNOPSIS
#include <fcntl.h> res = fcntl(fd, cmd, arg) int res; int fd, cmd, arg; DESCRIPTION
Fcntl provides for control over descriptors. The argument fd is a descriptor to be operated on by cmd as follows: F_DUPFD Return a new descriptor as follows: Lowest numbered available descriptor greater than or equal to arg. Same object references as the original descriptor. New descriptor shares the same file pointer if the object was a file. Same access mode (read, write or read/write). Same file status flags (i.e., both file descriptors share the same file status flags). The close-on-exec flag associated with the new file descriptor is set to remain open across execv(2) system calls. F_GETFD Get the close-on-exec flag associated with the file descriptor fd. If the low-order bit is 0, the file will remain open across exec, otherwise the file will be closed upon execution of exec. F_SETFD Set the close-on-exec flag associated with fd to the low order bit of arg (0 or 1 as above). F_GETFL Get descriptor status flags, as described below. F_SETFL Set descriptor status flags. F_GETOWN Get the process ID or process group currently receiving SIGIO and SIGURG signals; process groups are returned as negative values. F_SETOWN Set the process or process group to receive SIGIO and SIGURG signals; process groups are specified by supplying arg as nega- tive, otherwise arg is interpreted as a process ID. The flags for the F_GETFL and F_SETFL flags are as follows: O_NONBLOCK Non-blocking I/O; if no data is available to a read call, or if a write operation would block, the call returns -1 with the error EWOULDBLOCK. O_APPEND Force each write to append at the end of file; corresponds to the O_APPEND flag of open(2). O_ASYNC Enable the SIGIO signal to be sent to the process group when I/O is possible, e.g., upon availability of data to be read. RETURN VALUE
Upon successful completion, the value returned depends on cmd as follows: F_DUPFD A new file descriptor. F_GETFD Value of flag (only the low-order bit is defined). F_GETFL Value of flags. F_GETOWN Value of file descriptor owner. other Value other than -1. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
Fcntl will fail if one or more of the following are true: [EBADF] Fildes is not a valid open file descriptor. [EMFILE] Cmd is F_DUPFD and the maximum allowed number of file descriptors are currently open. [EINVAL] Cmd is F_DUPFD and arg is negative or greater than the maximum allowable number (see getdtablesize(2)). [ESRCH] Cmd is F_SETOWN and the process ID given as argument is not in use. SEE ALSO
close(2), execve(2), getdtablesize(2), open(2), sigvec(2) BUGS
The asynchronous I/O facilities of O_NONBLOCK and O_ASYNC are currently available only for tty and socket operations. 4.2 Berkeley Distribution Nov 30, 1994 FCNTL(2)
All times are GMT -4. The time now is 02:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy