Sponsored Content
Full Discussion: Bug has developed
Top Forums Programming Bug has developed Post 302128168 by arjunjag on Monday 23rd of July 2007 06:39:24 AM
Old 07-23-2007
Bug has developed

Guys there is another bug that has developed.........now messaged above 6 bytes are trimmed and echoed back to client.After the first message the echo is not regular.I have put a loop in both client and server to check for closing.Moreover for connection close i also need to put another clause that if there is a connection break in either server or client the connection should be closed from other side.Below are the server and clinet side codes after connection

Server
Code:
 while(j!=0)
    {
      memset(buffer,0,1024);/*clear buffer*/
      n = read(newsockfd,buffer,1024);/*read from client*/
      if (n < 0) perror("\n ERROR reading from socket \n");/*check for errors*/
      len=strlen(buffer);
      for(i=0;i<=len;i++)
	{
	  //strcpy(buf1,&buffer[i]);
	  //strcat(buf1,&buffer[i+1]);
	  k= strcmp("/",&buffer[i]);
	
	  if(k==0)
	    break;
	  break;
	}
	      for(p=i;p<=len;p++)
		{
		  j= strcmp("q",&buffer[p]);
		
	      if(j==0)
		{
		  close(newsockfd);
		  close(sockfd);
		  exit(0);
		  
		}
		}
	
	      puts(buffer);/*print message by client*/
	      write(newsockfd,"\n Client wrote",14);/*write to client*/
	      n=write(newsockfd,buffer,sizeof(buffer));/*write to client*/
	      if(n<0)perror("Write Failed");
	
      
    }

Client Side
Code:
	while(k!=0)
	  {
	    memset(&buf, 0, sizeof(buf));
    printf("\n Enter Message for Server");
    gets(buf);
    rc = write(s, buf,sizeof(buf)); 
     if(rc<0)
      {
	perror("write failed");
      }
    /* now that we are connected, start writing to the socket */	
    /* till write() returns 0, meaning the server closed	*/
    /* the connection.				*/
    len=strlen(buf);
    for(i=0;i<=len;i++)
      {
	//strcpy(b1,&buf[i]);
	//strcat(b1,&buf[i+1]);
	       
	l= strcmp("/",&buf[i]);
      
	if(l==0)
	  break;
	break;
      }
	    for(p=i;p<=len;p++)
	      {
	    k=  strcmp("q",&buf[p]);
	    if(k==0)
	      {
		close(s);
		exit (0);
	      }
	      }

	    read(s,buf1,14);
	    read(s,buf2,1024);
	    puts(buf1);/*print messages from server*/
	    puts(buf2);/*print messages from server*/
    
    
	  }
      }


Last edited by reborg; 07-23-2007 at 09:03 AM.. Reason: code tags
 

6 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

How was the Gollum Developed?

Can you please tell me how Gollum was created for a forum? I know of the ALICE and other bots but integrating the interface has always been my wish... Can someone give me some pointers on how to achieve this? (2 Replies)
Discussion started by: Legend986
2 Replies

2. Shell Programming and Scripting

New wrapper script will be developed to wrap two ksh scripts

Hi friend,:) The script should invoke these scripts sequentially! When one will finish the second will start. Please help me with it, thanks,:b: Ishai (3 Replies)
Discussion started by: ishai82
3 Replies

3. AIX

bug in 43 ???

xxxxserver# lsattr -El inet0 | grep 255.240.0.0,32.224.0.0,32.78.120.254 | grep '.40' route net,-hopcount,1,-netmask,255.240.0.0,32.224.0.0,32.78.120.254 How this is possible? (1 Reply)
Discussion started by: itik
1 Replies

4. Shell Programming and Scripting

How should this code be developed?

i'm trying to test whether wget is working still or not. while <----- how should this look please. do codes done (4 Replies)
Discussion started by: garfish
4 Replies

5. UNIX for Dummies Questions & Answers

How can I rebuild applications that developed in UNIX? I need to use it in windows os with cygwin

I need to rebuild an application that developed in unix environment and run in windows OS with cygwin. so How can I rebuild from the source code? is there any one who said something on this regard? (2 Replies)
Discussion started by: bejirond
2 Replies

6. OS X (Apple)

Can a ios app be developed on a windows or ipad?

hi, i want to start developing an ios app that can be used on iphone and ipad. can anyone guide me how to start? i saw that it can be developed only on a mac system.. but i dont have a mac system. i have an ipad 4 and a laptop with windows os? can i use one of these to start developing ios app??... (4 Replies)
Discussion started by: Little
4 Replies
socket(n)						       Tcl Built-In Commands							 socket(n)

__________________________________________________________________________________________________________________________________________________

NAME
socket - Open a TCP network connection SYNOPSIS
socket ?options? host port socket -server command ?options? port _________________________________________________________________ DESCRIPTION
This command opens a network socket and returns a channel identifier that may be used in future invocations of commands like read, puts and flush. At present only the TCP network protocol is supported; future releases may include support for additional protocols. The socket command may be used to open either the client or server side of a connection, depending on whether the -server switch is specified. Note that the default encoding for all sockets is the system encoding, as returned by encoding system. Most of the time, you will need to use fconfigure to alter this to something else, such as utf-8 (ideal for communicating with other Tcl processes) or iso8859-1 (useful for many network protocols, especially the older ones). CLIENT SOCKETS
If the -server option is not specified, then the client side of a connection is opened and the command returns a channel identifier that can be used for both reading and writing. Port and host specify a port to connect to; there must be a server accepting connections on this port. Port is an integer port number (or service name, where supported and understood by the host operating system) and host is either a domain-style name such as www.sunlabs.com or a numerical IP address such as 127.0.0.1. Use localhost to refer to the host on which the command is invoked. The following options may also be present before host to specify additional information about the connection: -myaddr addr Addr gives the domain-style name or numerical IP address of the client-side network interface to use for the connection. This option may be useful if the client machine has multiple network interfaces. If the option is omitted then the client-side interface will be chosen by the system software. -myport port Port specifies an integer port number (or service name, where supported and understood by the host operating system) to use for the client's side of the connection. If this option is omitted, the client's port number will be chosen at random by the system soft- ware. -async The -async option will cause the client socket to be connected asynchronously. This means that the socket will be created immedi- ately but may not yet be connected to the server, when the call to socket returns. When a gets or flush is done on the socket before the connection attempt succeeds or fails, if the socket is in blocking mode, the operation will wait until the connection is com- pleted or fails. If the socket is in nonblocking mode and a gets or flush is done on the socket before the connection attempt suc- ceeds or fails, the operation returns immediately and fblocked on the socket returns 1. SERVER SOCKETS
If the -server option is specified then the new socket will be a server for the port given by port (either an integer or a service name, where supported and understood by the host operating system). Tcl will automatically accept connections to the given port. For each con- nection Tcl will create a new channel that may be used to communicate with the client. Tcl then invokes command with three additional arguments: the name of the new channel, the address, in network address notation, of the client's host, and the client's port number. The following additional option may also be specified before host: -myaddr addr Addr gives the domain-style name or numerical IP address of the server-side network interface to use for the connection. This option may be useful if the server machine has multiple network interfaces. If the option is omitted then the server socket is bound to the special address INADDR_ANY so that it can accept connections from any interface. Server channels cannot be used for input or output; their sole use is to accept new client connections. The channels created for each incoming client connection are opened for input and output. Closing the server channel shuts down the server so that no new connections will be accepted; however, existing connections will be unaffected. Server sockets depend on the Tcl event mechanism to find out when new connections are opened. If the application doesn't enter the event loop, for example by invoking the vwait command or calling the C procedure Tcl_DoOneEvent, then no connections will be accepted. If port is specified as zero, the operating system will allocate an unused port for use as a server socket. The port number actually allo- cated my be retrieved from the created server socket using the fconfigure command to retrieve the -sockname option as described below. CONFIGURATION OPTIONS
The fconfigure command can be used to query several readonly configuration options for socket channels: -error This option gets the current error status of the given socket. This is useful when you need to determine if an asynchronous connect operation succeeded. If there was an error, the error message is returned. If there was no error, an empty string is returned. -sockname This option returns a list of three elements, the address, the host name and the port number for the socket. If the host name cannot be computed, the second element is identical to the address, the first element of the list. -peername This option is not supported by server sockets. For client and accepted sockets, this option returns a list of three elements; these are the address, the host name and the port to which the peer socket is connected or bound. If the host name cannot be computed, the second element of the list is identical to the address, its first element. SEE ALSO
fconfigure(n), flush(n), open(n), read(n) KEYWORDS
bind, channel, connection, domain name, host, network address, socket, tcp Tcl 8.0 socket(n)
All times are GMT -4. The time now is 04:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy