Sponsored Content
Full Discussion: socket programming
Special Forums IP Networking socket programming Post 302096723 by !_30 on Friday 17th of November 2006 12:48:11 PM
Old 11-17-2006
How to check the conectivity ? You mean , if socket client connection goes well or wrong ?

Code:
if( connect(listener,(struct sockaddr *) &myaddr, sizeof(myaddr)) < 0)
        {
                  perror("Error on connection , please reconnect later !");
                  exit(2);
        }

If (< 0 ) is error , in connection . Supose you pre-declared , something like this .. in the client cont ..


[code]
#define PORT 1957 /* aleator port */

struct sockaddr_in myaddr; /* your address structure */


myaddr.sin_family = AF_INET;
myaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
myaddr.sin_port = htons(PORT);

Listener , is the socket descriptor for the client .. something like this :


Code:
listener = socket(AF_INET, SOCK_STREAM, 0);

I mean , is AF_INET , but you can use AF_LOCAL , your using it only on your local computer/server .. SOCK_STREAM is for TCP ..


Maybe that was your problem ?
 

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. 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. IP Networking

socket programming

Hello Everyone Iam working on tcp/ip programming.with some time interval server has to send data.client has to close the connection and to open the connection between the time interval.this is the scenario when iam closing the connection in client side the connection terminates.how to... (1 Reply)
Discussion started by: sureshvaikuntam
1 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 Advanced & Expert Users

socket programming

can we send udp message to a destination ip address .. without having an ip address configured in our machine using recvfrom ? (2 Replies)
Discussion started by: Gopi Krishna P
2 Replies

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

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

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

10. Programming

socket programming

how to include socket.h in visual studio 2005.. (2 Replies)
Discussion started by: asd123
2 Replies
Tcl_OpenTcpClient(3)					      Tcl Library Procedures					      Tcl_OpenTcpClient(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_OpenTcpClient, Tcl_MakeTcpClientChannel, Tcl_OpenTcpServer - procedures to open channels using TCP sockets SYNOPSIS
#include <tcl.h> Tcl_Channel Tcl_OpenTcpClient(interp, port, host, myaddr, myport, async) Tcl_Channel Tcl_MakeTcpClientChannel(sock) Tcl_Channel Tcl_OpenTcpServer(interp, port, myaddr, proc, clientData) ARGUMENTS
Tcl_Interp *interp (in) Tcl interpreter to use for error reporting. If non-NULL and an error occurs, an error message is left in the interpreter's result. int port (in) A port number to connect to as a client or to listen on as a server. const char *host (in) A string specifying a host name or address for the remote end of the connection. int myport (in) A port number for the client's end of the socket. If 0, a port number is allocated at random. const char *myaddr (in) A string specifying the host name or address for network interface to use for the local end of the connection. If NULL, a default interface is chosen. int async (in) If nonzero, the client socket is connected asynchronously to the server. ClientData sock (in) Platform-specific handle for client TCP socket. Tcl_TcpAcceptProc *proc (in) Pointer to a procedure to invoke each time a new connection is accepted via the socket. ClientData clientData (in) Arbitrary one-word value to pass to proc. _________________________________________________________________ DESCRIPTION
These functions are convenience procedures for creating channels that communicate over TCP sockets. The operations on a channel are described in the manual entry for Tcl_OpenFileChannel. TCL_OPENTCPCLIENT Tcl_OpenTcpClient opens a client TCP socket connected to a port on a specific host, and returns a channel that can be used to communicate with the server. The host to connect to can be specified either as a domain name style name (e.g. www.sunlabs.com), or as a string contain- ing the alphanumeric representation of its four-byte address (e.g. 127.0.0.1). Use the string localhost to connect to a TCP socket on the host on which the function is invoked. The myaddr and myport arguments allow a client to specify an address for the local end of the connection. If myaddr is NULL, then an interface is chosen automatically by the operating system. If myport is 0, then a port number is chosen at random by the operating system. If async is zero, the call to Tcl_OpenTcpClient returns only after the client socket has either successfully connected to the server, or the attempted connection has failed. If async is nonzero the socket is connected asynchronously and the returned channel may not yet be connected to the server when the call to Tcl_OpenTcpClient returns. If the channel is in blocking mode and an input or output operation is done on the channel before the connection is completed or fails, that operation will wait until the connection either completes success- fully or fails. If the channel is in nonblocking mode, the input or output operation will return immediately and a subsequent call to Tcl_InputBlocked on the channel will return nonzero. The returned channel is opened for reading and writing. If an error occurs in opening the socket, Tcl_OpenTcpClient returns NULL and records a POSIX error code that can be retrieved with Tcl_GetErrno. In addition, if interp is non-NULL, an error message is left in the interpreter's result. The newly created channel is not registered in the supplied interpreter; to register it, use Tcl_RegisterChannel. If one of the standard channels, stdin, stdout or stderr was previously closed, the act of creating the new channel also assigns it as a replacement for the stan- dard channel. TCL_MAKETCPCLIENTCHANNEL Tcl_MakeTcpClientChannel creates a Tcl_Channel around an existing, platform specific, handle for a client TCP socket. The newly created channel is not registered in the supplied interpreter; to register it, use Tcl_RegisterChannel. If one of the standard channels, stdin, stdout or stderr was previously closed, the act of creating the new channel also assigns it as a replacement for the stan- dard channel. TCL_OPENTCPSERVER Tcl_OpenTcpServer opens a TCP socket on the local host on a specified port and uses the Tcl event mechanism to accept requests from clients to connect to it. The myaddr argument specifies the network interface. If myaddr is NULL the special address INADDR_ANY should be used to allow connections from any network interface. Each time a client connects to this socket, Tcl creates a channel for the new connection and invokes proc with information about the channel. Proc must match the following prototype: typedef void Tcl_TcpAcceptProc( ClientData clientData, Tcl_Channel channel, char *hostName, int port); The clientData argument will be the same as the clientData argument to Tcl_OpenTcpServer, channel will be the handle for the new channel, hostName points to a string containing the name of the client host making the connection, and port will contain the client's port number. The new channel is opened for both input and output. If proc raises an error, the connection is closed automatically. Proc has no return value, but if it wishes to reject the connection it can close channel. Tcl_OpenTcpServer normally returns a pointer to a channel representing the server socket. If an error occurs, Tcl_OpenTcpServer returns NULL and records a POSIX error code that can be retrieved with Tcl_GetErrno. In addition, if the interpreter is non-NULL, an error message is left in the interpreter's result. The channel returned by Tcl_OpenTcpServer cannot be used for either input or output. It is simply a handle for the socket used to accept connections. The caller can close the channel to shut down the server and disallow further connections from new clients. TCP server channels operate correctly only in applications that dispatch events through Tcl_DoOneEvent or through Tcl commands such as vwait; otherwise Tcl will never notice that a connection request from a remote client is pending. The newly created channel is not registered in the supplied interpreter; to register it, use Tcl_RegisterChannel. If one of the standard channels, stdin, stdout or stderr was previously closed, the act of creating the new channel also assigns it as a replacement for the stan- dard channel. PLATFORM ISSUES
On Unix platforms, the socket handle is a Unix file descriptor as returned by the socket system call. On the Windows platform, the socket handle is a SOCKET as defined in the WinSock API. SEE ALSO
Tcl_OpenFileChannel(3), Tcl_RegisterChannel(3), vwait(n) KEYWORDS
client, server, TCP Tcl 8.0 Tcl_OpenTcpClient(3)
All times are GMT -4. The time now is 04:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy