Network programming help required

Hi there.
I found an example of a radias calculator program that sends results to and from the client/multi threaded server.
I am trying to ammend it so I can send text to server, and echos that back to the client.
So far I am not having much luck at all trying to get this to work. I have seen examples in the tutorial, but I find them radically complicated.
If any experts out there could correct the below, that would be great!!
thanks
CLIENT
// Client.java: The client sends the input to the server and receives
// result back from the server
import java.io.*;
import java.net.*;
public class Client
// Main method
public static void main(String[] args)
try
     BufferedReader ar = null;
     BufferedWriter wr = null;
// Create a socket to connect to the server
Socket connectToServer = new Socket("localhost", 8000);
// Socket connectToServer = new Socket("bellamy.armstrong.edu", 8000);
          //ar = new BufferedReader(new InputStreamReader(new FileInputStream(UserName+ ".txt")));
// Create an input stream to receive data from the server
//DataInputStream isFromServer = new DataInputStream(connectToServer.getInputStream());
          ar = new BufferedReader(new InputStreamReader(connectToServer.getInputStream()));
// Create an output stream to send data to the server
//DataOutputStream osToServer = new DataOutputStream(connectToServer.getOutputStream());
wr = new BufferedWriter(new OutputStreamWriter(connectToServer.getOutputStream()));
// Continuously send radius and receive area from the server
while (true)
// Read the radius from the keyboard
System.out.print("Please enter a radius: ");
//double radius = 5574.5587;     //MyInput.readDouble();
String radius = "55745587";     //MyInput.readDouble();
// Send the radius to the server
//osToServer.write();
//osToServer.flush();
wr.write(radius);
wr.flush();
// Get area from the server
//String area = isFromServer.read("dsds");
String area = ar.read(" ");
// Print area on the console
System.out.println("Area received from the server is "
+ area);
catch (IOException ex)
System.err.println(ex);
MULTI THREADED SERVER
// MultiThreadsServer.java: The server can communicate with
// multiple clients concurrently using the multiple threads
import java.io.*;
import java.net.*;
public class MultiThreadServer
// Main method
public static void main(String[] args)
try
// Create a server socket
ServerSocket serverSocket = new ServerSocket(8000);
// To number a client
int clientNo = 1;
while (true)
// Listen for a new connection request
Socket connectToClient = serverSocket.accept();
// Print the new connect number on the console
System.out.println("Start thread for client " + clientNo);
// Find the client's hostname, and IP address
InetAddress clientInetAddress = connectToClient.getInetAddress();
System.out.println("Client " + clientNo + "'s hostname is "
+ clientInetAddress.getHostName());
System.out.println("Client " + clientNo + "'s IP Address is "
+ clientInetAddress.getHostAddress());
// Create a new thread for the connection
HandleAClient thread = new HandleAClient(connectToClient, clientNo);
// Start the new thread
thread.start();
// Increment clientNo
clientNo++;
catch(IOException ex)
System.err.println(ex);
// Define the thread class for handling a new connection
class HandleAClient extends Thread
private Socket connectToClient; // A connected socket
private int clientNo; // Indicate client no
// Construct a thread
public HandleAClient(Socket socket, int clientNo)
connectToClient = socket;
this.clientNo = clientNo;
// Implement the run() method for the thread
public void run()
try
// Create data input and output streams
// DataInputStream isFromClient = new DataInputStream(connectToClient.getInputStream());
// DataOutputStream osToClient = new DataOutputStream(connectToClient.getOutputStream());
     BufferedReader isFromClient = new BufferedReader(new InputStreamReader(connectToClient.getInputStream()));
BufferedWriter osToClient = new BufferedWriter(new OutputStreamWriter(connectToClient.getOutputStream()));
// Continuously serve the client
while (true)
// Receive radius from the client
String radius = "sss";
isFromClient.read();
System.out.println("radius received from client " +
clientNo + ": " + radius);
// Compute area
String area = radius;
// Send area back to the client
osToClient.write(area);
System.out.println("Area found: " + area);
catch(IOException ex)
System.err.println(ex);

Maybe I missed it, but I don't see a osToClient.flush() in the server. Without it the output will just build up.

Similar Messages

  • Desperately need Java network programming help!!!

    I need to make a Distributed File Sharing System (DFSS) using java language. The system should not make use of the central file server. The system should coordinate the concurrent access of files over the distributed environment. Caching may be used to enhance the system performance.
    It is basically network programming.
    Does any one have any idea how to make the DFSS. If you do please help!!!
    thank you in advance for you help
    cheers

    well, you're getting somewhere I guess. My original answer was intentionally vague because your original question was so vague. These fora are no good for asking questions like "how do I implement a distributed file system", they are good for asking things like "the following line(s) of code generate the following condition I didn't expect, rather I expected this condition, could someone tell me what is going on?" or something of similar specificity.
    So you are now asking how to, for instance, check to see if a text file is being shared. This is still too vague, but it's better than "how do I write a file sharing system". If you are feeling particularly industrious, go look at a project JXTA at http://www.jxta.org/ - it's open source, you can look at the code. Of course, if you're brand new, this might not help. In fact, not to discourage you, but if you're that new, this is not the project to be doing.
    Good Luck
    Lee

  • Object Oriented Programming - help required to find training material

    Hi,
    I am working in ABAP for 4 years. I did not get any chance to work in OOPs concept.
    However I know how to create classes,methods and how to access methods and attributes of class inside the report program and I hope apart from these we are having many things to learn OOPs ABAP.
    Can anyone help me to find OOPs training materials with examples?
    Thanks

    Hi Colleen,
    This is to inform you that, I am not expecting SCN or anyone to spoon feed me. I believe in IT industry Spoon feeding is not going to help in long time to survive. I am also using google,scn,sap technical.com and so many sites for my queries and learning.Please remember I am working in IT for long. Why should I expect people to spoon feed me.
    I have posted this question, because already many people might have searched and got some good and best articles with examples. So by believing that I will get good articles from the experts I have posted, but not for spoon feeding.
    I agree that whatever you have pointed in this post are good suggestion, but please before answering to such issues, please think in which situation they are seeking other's help. 
    Everyone's time is very precious. So I will not waste anyone's time and I will not waste my time too. I am not here to raise any concern on anyone. I just needed some help and got from the experts too.
    Instead of making this discussion to grow further, kindly close this here itself or remove this thread. I did not expect such sort of communication for asking the best training material for learning OOPs ABAP.
    Thanks

  • LED phidget programming help required

    Heyya
    I am a very new user in labview and for my project I need to control an LED phidget. Currently I am able to initialize the phidget and set in values to which LED to light up.
    What I require is i only want the particular LED to light up for a matter of 10 sec and then switch off. Currently the LED lights up but does not go off and stays on indefinitely and on selecting another LED number the earlier one continues to stay light up. Anyone any ideas for solution to this problem.

    djpal wrote:
    I am a very new user in labview and for my project I need to control an LED phidget.
    OK, a phidget is something physical, so apparently you have LED hardware and switches. What kind of DAQ hardware are you using? Are you using digital IOs? How are you setting the value that determines which LED to light? (A bank of switches with one switch for each LED? a rotary selector, etc.)
    It would really help if you could show us the code you have so far. Also, what is your LabVIEW version?
    I any case, what has been posted here so far are virtual implementations. You should be able to re-use part of the code. All you basically need is to translate the physical input to a number and the boolean array to something that light the LEDs accordingly.
    Better code only updates the digital output if the value actually has changed, and not 10x/sec. An event structure might be a better choice for that reason (See attached, LabVIEW 2010).
    At the moment, your specifications are full of holes and many scenarios need to be better defined:
    What should happen if a second LED is lit while the first one is still on?
    What should happen if the wait time is changed while a LED is already lit?
    Can multiple LEDs be ON, each with it's own timeout?
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Timed LED lightingMOD_EVENT.vi ‏12 KB

  • Help required network configuration - Gateway route settings get erased on reboot.

    Oracle Linux 7
    Linux myhostname 3.8.13-35.3.1.el7uek.x86_64 #2 SMP Wed Jun 25 15:27:43 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux
    #cat /etc/sysconfig/network-scripts/ifcfg-eno16780032
    TYPE="Ethernet"
    BOOTPROTO="none"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="no"
    IPV6INIT="yes"
    IPV6_AUTOCONF="yes"
    IPV6_DEFROUTE="yes"
    IPV6_FAILURE_FATAL="no"
    NAME="eno16780032"
    UUID="2d1107e3-8bd9-49b1-b726-701c56dc368b"
    ONBOOT="yes"
    IPADDR0="34.36.140.86"
    PREFIX0="22"
    GATEWAY0="34.36.143.254"
    DNS1="34.36.132.1"
    DNS2="34.34.132.1"
    DOMAIN="corp.halliburton.com"
    HWADDR="00:50:56:AC:3F:F9"
    IPV6_PEERDNS="yes"
    IPV6_PEERROUTES="yes"
    NM_CONTROLLED="no"
    #route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         34.36.143.254   0.0.0.0         UG    0      0        0 eno16780032
    34.36.140.0     0.0.0.0         255.255.252.0   U     0      0        0 eno16780032
    169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eno16780032
    When I reboot the machine, the first line in route table gets erased, I then run:
    #route add default gw 34.36.143.254
    After which network works fine.
    Help required. I don't want to use NetworkManager.

    The following might be useful:
    https://access.redhat.com/solutions/783533
    "When transitioning from NetworkManager to using the network initscript, the default gateway parameter in the interface's ifcfg file will be depicted as 'GATEWAY0'. In order for the ifcfg file to be compatible with the network initscript, this parameter must be renamed to 'GATEWAY'. This limitation will be addressed in an upcoming release of RHEL7."
    NetworkManager is now the default mechanism for RHEL 7. Personally I don't quite understand this, because as far as I can gather it is a program for systems to automatically detect and connect to known networks. I think such functionality can be useful when switching between wireless and wired networks, but for a server platform, I wonder.

  • Programs that require a network connection won't work because there is no virtual IP address available for this session.

    Programs that require a network connection won't work because there is no virtual IP address available for this session.  Per application IP virtualization is enabled.
    There are in fact available IP address's within the dhcp scope.  Before I dig to deep into root cause.. Could the problem be RDS CAL licensing running out, or isn't that not a symptom of my error message?

    Hi,
    Thank you for posting in Windows Server Forum.
    As per my research, there is no any issue related to RDS CAL licensing. Prior to the issue which you are facing, there are some basic setting which need to configure.
    Application Compatibility – Turn on Remote Desktop IP virtualization
    Some applications require a unique IP address, which is by default logically not the case if the application is running on RD Session Host. To solve this issue, Remote Desktop IP Virtualization is introduced. With this setting you enable the IP virtualization
    feature. When enabling this setting you need to specify if the virtual IP is provided per session or per program. When using per program you need to define the executable to which an IP address should be configured. Desktop IP virtualization also needs the
    configuration of the next setting.
    Application Compatibility – Select the network adapter to be used for Remote Desktop IP Virtualization
    When you need to use Remote Desktop IP virtualization configuring this setting is mandatory. You need to specify the IP address of the Network Interface Card which should be used for this feature. Besides the IP address you need also to specify the network
    mask using the slash notation, for example 192.168.77.201/24.
    Application Compatibility – Do not use Remote Desktop Session Host server IP address when virtual IP address is not available
    More information:
    Microsoft RDS Policies explained (Part 2)
    http://www.virtualizationadmin.com/articles-tutorials/vdi-articles/microsoft-hyper-v/microsoft-rds-policies-explained-part2.html
    Configuring Remote Desktop IP Virtualization II
    http://blogs.msdn.com/b/rds/archive/2009/07/15/configuring-remote-desktop-ip-virtualization-ii.aspx
    Hope it helps!
    Thanks.
    Dharmesh Solanki

  • HT3678 I am using a program which requires QuickTime version 7.7.2  I am finding it difficult to locate this item via download. Can anyone help?

    I am using a program which requires QuickTime version 7.7.2 specifically. Where can I find a download? Window 7 user.

    I'm assuming you know Quicktime 7.7.2 for Windows has been superceded by 7.7.4 available here;
    http://support.apple.com/downloads/#quicktime,
    and so the only place I could find the older version was at this link.
    http://news.softpedia.com/news/Download-QuickTime-7-7-2-for-Windows-269765.shtml

  • My MacBook Pro will not open any application or program that requires internet, even though I am connected to the web.

    My MacBook Pro will not open any app or program that requires Internet, even though I am connected to the web. I recently installed Norton AntiVirus and think it may have changed a setting that I couldn't find. I uninstalled Norton and it didn't help. Every time I open Safari, iTunes or any other program that tries to connect to the Internet, it crashes. Strangely enough, Skype still works, but nothing else.
    I have OSx 10.6.8.
    I have tried erasing plists, and all the standard troubleshooting, ie resetting modem, restarting computer, reloading Safari from disk.
    Any help would be greatly appreciated. Thank you in advance.

    Change your router channel.  Sometimes this is all you will have to do.
    Power cycling the router.  Read the router's user manual or contact their tech support for instructions.
    System Preferences/Internet & Network/Network
    Unlock the padlock
    Locations:  Automatic
    Highlight Airport
    Click the Assist Me button
    In the popup window click the Diagnostic button.
    System Preferences/Network- Unlock padlock.  Highlight Airport.  Network Name-select your name.  Click on the Advanced button.  Airport/Preferred Networks-delete all that is not your network.
    Place a check mark next to "Remember networks this computer has joined."  Click the OK button and lock the padlock.  Restart your computer.
    http://support.apple.com/kb/TS1920 Mac OS: How to release and renew a DHCP lease
    No internet connection (wireless)
    Check to see if an extra entry is present in the DNS Tab for your wireless connection (System Preferences/Network/Airport/Advanced/DNS).
    Delete all extra entries that you find.
    Place a check mark next to "Remember networks this computer has joined."
    Other resources to check into:
    Troubleshooting Wi-Fi issues in OS X Lion and Mac OS X v10.6
    Netspot
    How to diagnose and resolve Wi-Fi slow-downs
    Pv6 troubleshooting
    Mac OS X 10.6 Help:  Solving problems with connecting to the Internet
    What Affects Wireless Internet?
    Solutions for connecting to the Internet, setting up a small network, and troubleshooting
    I uninstalled Norton and it didn't help.
    To properly uninstall Norton software follow these instructions - Locate Symantic Solutions folder inside the Applications folder at the root level of your HD, launch the Symantec Uninstaller application, select the Symantec AntiVirus Corporate, Norton AntiVirus & Norton AntiVirus Auto-Protect entries and click the Uninstall button. 
    Confirm your decision when prompted and then enter your administrator password in the space provided.
    Retart your computer & Norton should be gone for good.
    If the above does not work, download a copy of Symantec’s RemoveSymantecMacFiles removal utility.  This utility will launch Terminal & remove the Norton components.

  • Network programming tips

    I am new to network programming can anybody give me some tips on ways to optimize speed of an application that gets data via sockets over the network?
    You can assume its just a simple program where the client that gets continuous data feeds of sales amounts from the server and I want to make this program run faster.
    I would appreciate any ideas.
    Thanks!!

    Peter__Lawrey wrote:
    kci wrote:
    I am new to network programming can anybody give me some tips on ways to optimize speed of an application that gets data via sockets over the network?Don't worry about it. Your network is much slower than your CPU so it doesn't matter so much what you do in Java.
    I suggest you test your network to see what its latency and bandwidth is e.g. ping or transfer a large file and work out what you requirements are for latency and bandwidth.
    It very likely that you won't need to anything special in Java.
    You can assume its just a simple program where the client that gets continuous data feeds of sales amounts from the server and I want to make this program run faster.You should get a better understanding of the end to end process which needs to be faster and where you can make the most improvement. You are likely to find the GUI doesn't handle large tables or you are missing an index in your database.
    In Summary: determine where you can make the most difference and optimise that.
    I would appreciate any ideas. Actually there are loads of things you can do to make the network faster, but I would only do them if you actually need to.
    If you have done this analysis already what conclusions have you come to?Thanks a lot Peter!!
    All the posts in this thread have been helpful but yours definitely is the main direction I am looking for so I appreciate.
    Please if you can go a little further and help me with these issues....
    I am designing an application that is suppose to get real time data feeds over the network. Now as you said the network is slower than the CPU... But what if I am aiming for a latency of 5ms (just for the sake of discussion) but I ping the network and I see the latency is 10ms.
    Is there a way in this case you suggest I can optimize the network to reduce the latency.
    And no I haven't done the analysis yet. I am designing an application but I have never done this type of application so I am brainstorming now and you all have really helped out a lot so far!!

  • Urgent help required: Query regarding LC Variables

    Hi All
    Sometime earlier I was working on a performance issue raised by a customer. It was shell script that was taking almost 8-9 hrs to complete. During my research I came across a fact that there were some variables which were not set, the LC variables were impacting the sort funnel operations because of which the script was taking a long time to execute.
    I asked them to export the following commands, after which the program went on smoothly and finished in a couple of mins:
    export LC_COLLATE=en_US.ISO8859-1
    export LC_MESSAGES=C
    export LC_MONETARY=en_US.ISO8859-1
    export LC_MONETARY=en_US.ISO8859-1
    export HZ=100
    export LC_CTYPE=en_US.ISO8859-1
    export LANG=en_US.UTF-8
    Later I did recover that setting the LC_COLLATE to C, is not helping and the program was again taking a lot of time. Few questions that I want to ask are:
    1. Can someone please tell me, what each of these variable mean and how these values make a difference.
    2. When I exported LC_COLLATE=en_US.ISO8859-1, it worked fine, but when i tried with the defalut value LC_COLLATE=C, then why the program didnt work.
    As this issue is still going on, hence I would request All to provide their valuable inputs and let me know as much as possible.
    Appreciate your help in this regard.
    Thanks
    Amit
    Hi All
    A new development in this regard. The customer has send us a screen shot in which they were trying to export the locale variable using the commands which I have pasted above. I can see in the screen shot that while exporting LC_COLLATE and LC_TYPE, they get a message that ""ksh: export: couldn't set locale correctly"".
    Request everyone to please give their inputs as it's a bit urgent.
    Thanks for all the help in advance.
    Thanks
    Amit
    Some help required please...
    Edited by: amitsinhaengg on Jul 22, 2009 2:03 AM
    Edited by: amitsinhaengg on Jul 22, 2009 2:06 AM

    LC_CTYPE
    Controls the behavior of character handling functions.
    LC_TIME
    Specifies date and time formats, including month names, days of the week, and common full and abbreviated representations.
    LC_MONETARY
    Specifies monetary formats, including the currency symbol for the locale, thousands separator, sign position, the number of fractional digits, and so forth.
    LC_NUMERIC
    Specifies the decimal delimiter (or radix character), the thousands separator, and the grouping.
    LC_COLLATE
    Specifies a collation order and regular expression definition for the locale.
    LC_MESSAGES
    Specifies the language in which the localized messages are written, and affirmative and negative responses of the locale (yes and no strings and expressions).
    You can use command
    # locale -k LC_CTYPE
    to see more detail about each type.

  • Installation problem any program that requires Adobe Air

    Installation problem
    I just purchased a new HP Pavilion Laptop running windows 8
    If I try to install any program that requires Adobe Air I get a failure message that says
    "Sorry an error has occured
    The applcation could not be installed because the installer file is damaged.  Try obtaining a new installer  file for the applciation author"
    I have version 14.0.0.110 of Adobe Air Installed.  
    I have installed all widows updates.
    I have removed and re installed Adobe Air but the problem persists
    Very frustrating problem, any help or direction is appreciated

    I have a similar problem and a possible workaround. Take a look at my reply: Installing air applications returns error

  • Help required with Photoshop Elements 4.0 this has been installed on my new Toshiba laptop with windows 8.1 for some 18 months and operating well. Now it will not open, message pops up saying "attempt to access invalid address" then "application not respo

    Help required with Photoshop Elements 4.0 this has been installed on my new Toshiba laptop with windows 8.1 for some 18 months and operating well. Now it will not open, message pops up saying “attempt to access invalid address” then “application not responding” Suggestions how to access would be much appreciated. Tks. Stuart

    What is the size of your hard disk?  PSE 4 is a very old program and I suspect it is not able to access the entire hard disk on your machine.  Just a thought here.

  • Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?

    Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?
    I'm developing an application where a file is need to be saved as pdf. But, if there is already a pdf file with same name in the specified directory, I wish to overwrite it. And in the overwrite case, read-only files should not be overwritten. If the duplicate(old) file is opened in windows (Win7) explorer preview, it is write protected. So, it should not be overwritten. I tried to get the '
    FILE_ATTRIBUTE_READONLY' using MS API 'GetFileAttributes', but it didn't succeed. How Adobe marks the file as read-only for preview? Do I need to check some other attribute of the file?
    Thanks!

    Divya - I have done it in the past following these documents. Please read it and try it it will work.
    Please read it in the following order since both are a continuation documents for the same purpose (it also contains how to change colors of row dynamically but I didnt do that part I just did the read_only part as your requirement) 
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0625002-596c-2b10-46af-91cb31b71393
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0155eb5-b6ce-2b10-3195-d9704982d69b?quicklink=index&overridelayout=true
    thanks!
    Jason PV

  • Help required with (soundcard) connection / settings, thanks in advan

    Help required with connection / settings between a Creative Sound Blaster Audigy Platinum EX (soundcard) and a Creative DTT3500 Digital (5. speakers).
    The problem
    No sound from any of the speakers. (Exception can plug in headphones at front)
    Background
    My computer has been recently upgraded at my local computer shop and all programs re-installed (including driver update from Creative's website). However after reconnecting speakers and restoring the original settings I?m getting no sound from any of the speakers. I?ve followed all the available advice/instructions I can find on this website and manuals to no avail.
    Set-up
    Physical
    (Digital DIN) Speakers/decoder amplifier (DTT3500) connected to the (digital out) soundcard (Audigy Platinum EX) using minijack to DIN cable. (As per instruction manual)
    Software
    Creative Audio Consul ? setting as per instructions, however have tried variations in vain. (Note: above tabs there is a select device box with SB Audigy [A0000] in it ? only option. Just wondering what [A0000] means?)
    Your advice please. A simple step by step guide would be appreciated, many thanks in advance, Jon

    "My computer has been recently upgraded at my local computer shop and all programs re-installed (including driver update from Creative's website). "
    Do you have the original installation disk?
    If so, try installing THOSE drivers, ESPECIALLY if it worked before. Be sure to uninstall what is there now, first.
    Its natural for most people to want the 'latest' drivers for their hardware. However:
    After experiencing some difficulties with some CL 'updates' for certain products, I now avoid them UNLESS I am having a PROBLEM with the existing drivers.

  • I have a program that requires Java 6.  I am running 10.8.2, How do I remove Java 7 to run this program?

    I have a program that requires Java 6.  I am running 10.8.2, How do I remove Java 7 to run this program?

    Try going to the Oracle site - they did have a page showing how to remove Java 7 using the terminal program.
    I followed their instructions and it didn't work for me, but you may have better skills and luck than I.
    This was my starign point;
    http://www.java.com/en/download/help/mac_uninstall_java.xml
    Let us know if this works.

Maybe you are looking for

  • How to create numeric attribute using ABAP API

    Hi experts I'm trying to create a numeric attribute for a taxonomy table. In the how-to-examples there are only ways to create text attributes. Those who have tried, please let me know the steps. I have given below the code snippet which i tried to c

  • How can i get a tv show clip into final cut pro x?

    say i download a tvshow clip from itunes, can i get that episode in FCP X?

  • Quick connection for external hard drive

    I have an internal hard drive which I want to quickly connect to my PB so I can initialise it and make a clone. I don't have an enclosure at the moment, and I'm sure I've seen a ribbon cable which enables you to attach the drive on its own to the fir

  • Itunes stops working every time I try to sync

    I get the message that itunes has stopped working and needs to be shut down everytime I try to sync my new ipad

  • Help with display glith using JList

    Hi, first post so bit of background - I'm teaching Java at the moment, am fine with command line but am dabbling more with Swing, despite certain glitches I always get ( e.g. the 7-segment display last year) but anyway.... I've been trying to develop