Results 1 to 6 of 6
  1. #1
    FatimaMirza is offline Member
    Join Date
    Nov 2016
    Posts
    3
    Rep Power
    0

    Default Need help in network programming

    Hello, I am Fatima.
    I need some help in network programming. I can't seem to find the relevant topic for this.
    Help please?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Need help in network programming

    What are your java programming questions?
    Be sure to wrap any code in code tags.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    FatimaMirza is offline Member
    Join Date
    Nov 2016
    Posts
    3
    Rep Power
    0

    Default Re: Need help in network programming

    Okay thank you so much.

    i am attempting to wwrite a code for single server multiple clients without threading. my logic is to use different for numbers.
    my code runs perfectly for single server single client. how can i modify this to incorporate multiple client w/o threading?

    Java Code:
    import java.io.*;
    import java.net.*;
    
    class TCPServer
    {
    	public static void main(String argv[]) throws Exception
    	{
    		String clientSentence;
    		String capitalizedSentence;
    		ServerSocket welcomeSocket= new ServerSocket(6789);
    		while (true)
    		{
    			Socket connectionSocket=welcomeSocket.accept();
    			BufferedReader inFromClient=
    				new BufferedReader(new InputStreamReader(
    					connectionSocket.getInputStream()));
    			DataOutputStream outToClient=
    				new DataOutputStream(
    					connectionSocket.getOutputStream());
    			clientSentence=inFromClient.readLine();
    			System.out.println("From Client: "+clientSentence);
    			capitalizedSentence=
    				clientSentence.toUpperCase()+'\n';
    
    			outToClient.writeBytes(capitalizedSentence);
    			
    		}
    		
    	}
    	
    }


    Java Code:
    package tcpmsg;
    
    
    
    
    import java.io.*;
    import java.net.*;
    class TCPClient
    {
    	public static void main(String argv[]) throws Exception
    	{
    		String sentence;
    		String modifiedSentence;
    
    		BufferedReader inFromUser=
    			new BufferedReader(new InputStreamReader(System.in));
    
    		InetAddress inetAddress=InetAddress.getLocalHost();
    		//.getByName(String hostname); "CL11"
    		System.out.println(inetAddress);
    
    		Socket clientSocket = new Socket(inetAddress,6789);
    		DataOutputStream outToServer=
    			new  DataOutputStream(clientSocket.getOutputStream());
    
    		BufferedReader inFromServer=
    			new  BufferedReader(new InputStreamReader
    							(clientSocket.getInputStream()));
    
    
    		sentence=inFromUser.readLine();
    		outToServer.writeBytes(sentence+'\n');
    
    		modifiedSentence=inFromServer.readLine();
    		System.out.println("From Server: "+modifiedSentence );
    		clientSocket.close();
    
    
    	}
    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Need help in network programming

    incorporate multiple client w/o threading?
    Why no threading? That is the natural solution for a server that must handle multiple clients concurrently.
    If handling clients one at a time (serially) would work, then there won't need to be threading.

    A problem with not using threads is the I/O streams can block waiting for input. I think that there are some non-blocking methods in the nio packages that I have never used.
    If you can get non-blocking I/O to work, then a server could handle multiple clients by polling a queue of clients to see if any of them have sent a request.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    FatimaMirza is offline Member
    Join Date
    Nov 2016
    Posts
    3
    Rep Power
    0

    Default Re: Need help in network programming

    Thank you for your prompt reply.
    I realize the importance of threading. However, I am trying to learn about blocking and non blocking I/O and see how they might work in codes. I am going to look into the nio packages. If you could give me a hint as to how I would poll the clients, it would be really helpful.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Need help in network programming

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 3
    Last Post: 07-22-2014, 01:16 AM
  2. network programming
    By anup1710 in forum Networking
    Replies: 0
    Last Post: 05-09-2011, 12:20 PM
  3. Replies: 7
    Last Post: 05-02-2010, 10:35 PM
  4. [SOLVED] Network Programming Using Datagrams
    By IandI in forum Networking
    Replies: 4
    Last Post: 03-17-2009, 11:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •