Try to use one comupter as both server and client

Hello, everyone, I am just trying to use my own computer as both server and client to test some codes about networking. For example, use the sample code in java tutorial which is used to test Echo server(code is listed below). Is there anything I have to do to set my computer, such as set my hostname or something like that?
I am a pure newbie. And the purpose of this question is to test some code including socket on one PC without connect to internet.
I have tried to change the name "taranis" in the following code to the computer name of my own PC, but it doesn't work, and said: Couldn't get I/O for the connection to: (my computer name).
import java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("taranis", 7);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: taranis.");
System.exit(1);
     BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
     String userInput;
     while ((userInput = stdIn.readLine()) != null) {
     out.println(userInput);
     System.out.println("echo: " + in.readLine());
     out.close();
     in.close();
     stdIn.close();
     echoSocket.close();

Did you write the EchoServer and start it on your
machine, listening on port 7?
You can have the client and server running on the same
machine or different machines, but they have to be
separate pieces of software.
Write a separate EchoServer class that starts up and
listens on that port. Then start the EchoClient and
make the connection.
%yeah, I didn't wrote the EchoServer class. But I thought it is automaticly included and therefore has run once I start my computer.
If I write a EchoServer class, then how should I set the host name of the EchoClient, just simply change "taranis" to my computer name (change "echoSocket = new Socket("taranis", 7);" to echoSocket = new Socket("(my comptuer name)", 7);"?

Similar Messages

  • How can a VI be both server and client?

    Hi, 
    I'm new in LabView and I'm trying to build a server and client VI using TCP/IP that runs in two computers. in my program I need both server and client VIs to communicate with each other which means I need both VIs to be server and client. I've tried using a case structure but it doesnt work. The only thing I achieved is a normal server/client system where the server sends a request and the client responses.But i need the client to send requests too.i have attached my VIs to this post.I would appriciate it if someone could help with this problem. 
    Thanks in advanced. 
    Rambaldi.
    Solved!
    Go to Solution.
    Attachments:
    Server-Client.zip ‏41 KB

    Do you really need a client and server on each PC? If you simply need that two to talk to each other they can once the client connects to the server. In most cases you only need one server.
    What Steve said about the not using the same port only applies to two servers on the same machine. A client must use the port the server is listening to and if the client and the server are on the same machine then they will both use the same port. However, only ONE of them is accepting waiting for connections on that port.
    In the code you posted you actually swapped the names. What you call the client is actually the server code and vise versa. In networking a server is an application that listens to an assigned port, accepts connections on that port and provides whatever services it has implemented. A client is an application that establishs a connection to a server. Once a connection is established the two applications can communicate in both directions. The applications themselves will define how the conversation should progress and whether it is a one way conversation or a two way conversation. You don't specify what you are trying to accomplish but I suspect you only need a single server.
    In TCP, every connection is defined by the source and destination IP addresses and the source and destination ports. The server uses a known port (FTP is port 21, HTTP is 80, telnet is 23, or some custom port in the user space beyonds the reserved ports) to listen for connections. The client will use the well known port of teh server and generally picks a random port for its port number. The LabVIEW VIs do this automatically. This is how a server and a client on the same computer can use the same port number. Two servers however cannot. The server application can spawn a child task allowing it to service multiple connections at one time though. Each connection will be unique though since the client's port number, address or both will change for each connection.
    OK, end of networking 101.
    Can you describe in a bit more detail what exactly you want to accomplish. Given that I could probably provide you with more information for your application.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Comprised of both server and client components

    Hello all
    We all consult an open source project and download freely the source code and the documentation for the server as a tarball. The well known open source project is Paragent which its platform is comprised of both server and client components written in Lisp, C++ and Java. just take a look and drop your suggestions.
    Thanks for any help,
    Bmora96

    Huh?

  • Any idea how you can safely use ONE computer for BOTH work and internet?

    I'm planning to set up a small music project studio, built around a powerbook, that I will be sharing with a friend of mine. My friend is going to use the computer for music AND heavy internet use, but I will only use it for music work (off-line).
    The thing is then that I am slightly worried about viruses, worms, spyware and similar unwanted stuff 'sneaking in' when the laptop is online. Even with firewall and anti-virus I guess there is always a risk.
    Any idea if there is a way of keeping things completely separate?
    How about if I had a bootable external hard drive for my work, with the Mac OS system on. Then when I'm working I could boot up from that drive (and use the computer off-line).
    Maybe we could even remove the internal hard drive from the powerbook (?), and use the powerbook with two external hard drives instead: One bootable drive for me and another bootable drive for my studio partner (and then only connect one hard drive at the time).
    Any idea if this would work well..? (I'm not sure if i.e. a virus could sneak in anyway, through the PRAM, L2 cache or the RAM or something similar) Or does anyone have any other suggestions...? Any ideas much appreciated. Thanks!

    Not too much worry with Macs, but get an Ethernet Router, skip Wireless, use strong Passwords.
    How about if I had a bootable external hard drive for my work, with the Mac OS system on. Then when I'm working I could boot up from that drive (and use the computer off-line).
    Excellent idea, especially if the heavy Net user doesn't have Admin rights.
    One bootable drive for me and another bootable drive for my studio partner (and then only connect one hard drive at the time).
    Just about foolproof! Just need 2 more drives for backup. Not sure why you'd want to remove the internal HD though.
    No Viruses yet in OSX land, in fact the only Malware I know about requires you to install it for itself!
    You'll be OK, that separate drives idea is pure genius.:-)
    Most don't need it on Macs, but here ya go on the Mac side...
    ClamXAV, free Virus scanner...
    http://www.clamxav.com/
    Little Snitch, stops/alerts outgoing stuff...
    http://www.obdev.at/products/littlesnitch/index.html
    HenWen/Snort combo, that is a free MAJOR Firewall...
    http://seiryu.home.comcast.net/henwen.html
    Then the venerable old Brickhoues/Flying Buttress Firewall...
    http://personalpages.tds.net/~brian_hill/downloads.html
    WaterRoof is a firewall management frontend with bandwidth tuning, NAT setup, port redirection, dynamic rules tracking, predefined rule sets, wizard, logs, statistics and other features.
    http://www.macupdate.com/info.php/id/23317
    Monitor net usage...
    http://mac.softpedia.com/get/Dashboard-Widgets/Information/Videotron-Internet-Us age-Monitor.shtml

  • JAX-RPC: Web service where both server /and/ client are services?

    I'm considering a two-way Web service in an application that I'm designing and would appreciate any insight from prior experience.
    This will be a standard client-server application, where the server broadcasts messages and the client, in turn, can request further information about the messages that it receives (think RSS-style updates, but with more interaction). [strong]However[strong], instead of having the client poll the server for new messages, I'd like to have the client register itself with the server as a message listener. The server is currently implemented as a Web service on port X. I'd like the client to register itself with the server, and then receive messages on port Y.
    I'm considering a design like the following (note the directions of the inheritance arrows):
    ( Server class )  --<-- ( RemoteServerImpl class ) -->-- / RemoteServer interface /
           |
    ( Listener class ) --<-- ( RemoteListenerImpl class ) -->-- / RemoteListener interface /Some considerations:
    * In both cases, the client and server are broken out into an interface and two classes. The non-Remote classes implement all of the functionality. The RemoteX interfaces declare the methods that will be exposed via RPC, and the RemoteXImpl classes are empty subclasses of the non-Remote classes.
    * In order to register itself with the Server, the Listener must be passed in as a method parameter, and thus conform to the JAX-RPC specification for value types. However, value types can't implement java.rmi.Remote.
    * Only the Server and Listener know anything about each other.
    * This application can be run either remotely or locally, depending on how the Server and Listener are instantiated. For the latter, they're instantiated directly and the listener is registered with the Server. For the latter, the RemoteX interfaces will point to the service stubs.
    * I don't see an easy way to allow both the Server and the Listener to have references to each other (at least now without some casting magic), since one of them will have to conform to the value type specification, which requires that all of its fields must be valid JAX-RPC types.
    I've got the Server portions implemented and working, and am now going to turn to the Listener stuff. Can anybody see a fundamental problem with this design, or can suggest something better?

    Hi There,
    Because web services are fundamentally a Services-oriented architecture, and not an Object-oriented one, you are unable to pass objects by reference (only by value) hence the design decision to not allow rmi.Remote objects to be sent across the wire. The best way would be to abstract an object which does itself not represent a server, but a route to a server (lets call it ServerPointer). This must contain address, port, service info, etc.
    Now, in your Server class, create a factory method which takes a ServerPointer, and returns a reference to a
    remote server, e.g. protected Server createServer( ServerPointer p ) (using the necessary APIs to get such a reference)
    Hope this helps...

  • I don't have idvd but i need to burn my movie from iMovie! what do i do? i have dvds but every time i try to use one, the sound is off and it doesn't work on quick time or adobe... help!!

    i have made a movie in imovie on my macbook pro, but apparently i don't have idvd!!!
    i need to burn this so i can watch it somewhere else, but im not sure how...
    ive already tried simply exporting it to Quick Time, and burned it to a dvd, but when i watched it... the sound was wrong and people's words were like muted...
    what do i do?!?! i don't know where or how to get idvd!
    help!!!

    Hi
    There are two structures of DVDs
    • Data-DVD - as burned from DeskTop/Finder
    • Video-DVD - to be played on a DVD-Player - Needs a program that can do this
    One can in iMovie - Export as QuickTime .mov and save this via DeskTop/Finder onto a DVD - BUT this will only play on a Computer and if it is a Window-PC this needs to download QT-player or VLC-player.
    But no DVD-player for TV can play back this.
    To get a Video-DVD then You need
    • iDVD (not from Apple any more) - or -
    • DVD Studio Pro (not from Apple any more) - or -
    • FinalCut Pro-X (can do simple Video-DVDs) - or -
    • Burn - http://www.digital-digest.com/software/Burn.html - FREE - but very PLAIN - no fancy things at all.
    • Roxio Toast™ 11 Pro - Fairly advanced - and costs a bit - still very Good and lot's of great tool's included. (I love it) - Can also back convert home made DVDs to an editable mode in an OK quality. With BD-component also capable to do sort of Blu-Ray DVDs.
    Yours Bengt W

  • Using one email for both husband and wife, how can we FaceTime each other

    My husband and I share an email account and Apple ID  How can we FaceTime each other since it seems to be based on our shared identity?  I am on a MacBook and he is on an iPad 2.

    have to use a different apple id.  sorry
    Peace, Clyde

  • Where can one fine TCP socet server and client example VI's for Labview 6.0

    We've inherited an older system containing two PXI systems and one PC.  The Labview -6.0 programs running on the three systems need to be rewritten from ground zero.
    In hopes of saving a great amount of time, I am looking for a couple of TCP socket VI's that can be used to set up communications between the applications.  There doesn't appear to be a backwards compatibility from examples found in newer versions of Labview.
    Thanks,
    KGTang

    kgtang wrote:
    We've inherited an older system containing two PXI systems and one PC.  The Labview -6.0 programs running on the three systems need to be rewritten from ground zero.
    In hopes of saving a great amount of time, I am looking for a couple of TCP socket VI's that can be used to set up communications between the applications.  There doesn't appear to be a backwards compatibility from examples found in newer versions of Labview. 
    Why backwards compatibility?
    Look in examples/comm/tcpex.llb. Those examples are still mostly unchanged in the newer LabVIEW versions too.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • One RTPManager for both, receiving and transmitting

    Can I use one RTPManager for both, receiving and transmitting media data?
    I would create send stream and imlement appropriate update+ methods.
    Will it work?
    Regards!

    Ummm, you don't have to implement any methods if you don't want. The default RTPManager does it all for you. I think you may want to override some trigger functions, but...
    [http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/AVTransmit.html]
    [http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/AVReceive.html]

  • MultiThreaded Server and Client connections query.

    I have written a MultiThreaded Server to accept incoming client requests.
    Multiple clients can connnect to this server and have a conversation.
    I invoke the 'MultiServer' from the command line and then invoke 3 clients
    from the command line.('Client').
    c:> java MultiServer
    c:> java Client
    c:> java Client
    c:> java Client
    All the 3 clients now run in their own thread and send messages
    to the server.
    The problem I am facing is this:
    When client1 connects to the server and sends a message to the server (with the server responding)
    it works fine.Both Server and Client can exchange messages.
    When client2 connects to the server and sends a message and when the server
    responds with a message,the message does NOT go to client2,but goes to Client1
    As Clients have their own thread to run,shouldnt the messages also be delivered to
    individual clients
    Am I missing something?
    My Code
    public class MultiServer {
        public static void main(String[] args) throws IOException {
            ServerSocket serverSocket = null;
            boolean listening = true;
            try {
                serverSocket = new ServerSocket(4444);
                System.out.println("MultiServer listening on Port 4444");
            } catch (IOException e) {
                System.err.println("Could not listen on port: 4444.");
                System.exit(-1);
            // Indefinite Loop.
            while (listening)
             new MultiServerThread(serverSocket.accept()).start();
            serverSocket.close();
    public class MultiServerThread extends Thread {
        private Socket socket = null;
        public MultiServerThread(Socket socket) {
         super("MultiServerThread");
         this.socket = socket;
        public void run() {
         try {
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                            socket.getInputStream()));
               BufferedReader stdInFromServer = new BufferedReader(new InputStreamReader(System.in));
            String fromTheClient,fromServer;
               fromServer = "Hi Client,How u doing? ";
            // Send a message from the Server.
               out.println(fromServer);
                while ((fromTheClient = in.readLine()) != null) {
                 if (fromTheClient.equals("ByeServer"))
                 break;
                 // Display message received from Client.
                 System.out.print("Client Response : ");
              System.out.println(fromTheClient);
                 // Input reply from the Server.
                 fromServer = stdInFromServer.readLine();
                 out.println(fromServer);
                 if (fromServer.equals("Bye."))
                    break;
             out.close();
             in.close();
             socket.close();
         } catch (IOException e) {
             e.printStackTrace();
    Client Code
    ===========
    public class Client {
        public static void main(String[] args) throws IOException {
            Socket kkSocket = null;
            PrintWriter out = null;
            BufferedReader in = null;
            try {
                kkSocket = new Socket("localhost", 4444);
                out = new PrintWriter(kkSocket.getOutputStream(), true);
                in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host: localhost.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to: localhost.");
                System.exit(1);
            BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
            String fromServer;
            String fromUser;
            while ((fromServer = in.readLine()) != null) {
                System.out.println("Server: " + fromServer);
                if (fromServer.equals("Bye."))
                    break;
                    fromUser = stdIn.readLine();
             if (fromUser != null) {
                    out.println(fromUser);
            out.close();
            in.close();
            stdIn.close();
            kkSocket.close();
    }

    Taking standard input for multiple threads from one console is quite unpredictable. I think the first client thread is waiting for input when you connect the second. You type something into your server window and since the first thread was waiting for input, it takes the input and sends it to client 1.

  • UDP server and client running on same machine

    Hi all,
    I can't get the QuoteServer example to work. I am trying to run both server and client on same machine since I only have one machin available at the moment.
    I am using win xp behind a firewall. Anything that might interfere?
    With some System outs I can see that the server is waiting for request but never getting any...

    Restarted computer and now it works. Are ports locked up if I get an exception in the 'wrong' place?

  • LDAP (Directory service) server and client compatiblw with windows 7

    Hello Experts,
    Earlier we were using Netscape Server 4.0 and Console  in Windows XP for LDAP Integration testing with BRM.
    Now that Windows XP is soon going to be decommissioned and the software is incompatible with windows 7,I am looking for Directory service (both server and client) alternatives compatible with Windows 7.
    Has  anyone tried setting up a Directory service(or LDAP) in windows 7 Operating system ??
    Any help is appreciated. Thank you

    Hello Mr Thio,
    Basic cause for this type of error message is Generally permission issue.If you are using a domain account make sure it is added as local administrator in local machine.
    RK on setup.exe and select run as administrator
    Makes sure you copy installables on local drive and run setup from machine if your are running from CD directly avoid it.
    Below MS link has documented this error please go through the link properly
    http://support.microsoft.com/kb/2799534
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • At home I have two wifi networks , I try to use one of them depending on their strength of signal, can I not save  both their passwords on Apple TV , so that I can switch to one of the two wifi networks as required

    At home I have two wifi networks , I try to use one of them depending on their strength of signal, can I not save  both their passwords on Apple TV , so that I can switch to one of the two wifi networks as required
    Also the passwords are long and cumbersome to type every time on the apple  TV remote, what is the alternative if I cannot store them on the memory of the Apple TV

    Is it possible that you are using the same password for the old O2 Study and newer O2 Apple Base Station networks?
    If so, Keychain Access is storing the old information about the old network and may be associating it with your AirPort Extreme settings based on the BSSID that William has mentioned.
    If that's the case, open Macintosh HD > Applications > Utilities > KeyChain Access and look for a listing with the old network name. Delete this entry. You may need to power down both the computer and the AirPort Extreme and restart them.

  • Can I use one account for both my labtop and my ho...

    can I use one account for both my labtop and my home computer?
    Solved!
    Go to Solution.

    Softthunder wrote:
    can I use one account for both my labtop and my home computer?
    Hello,
    Yes you can. You can access your account using any Skype enabled computer/device in any country worldwide.
    TIME ZONE - US EASTERN. LOCATION - PHILADELPHIA, PA, USA.
    I recommend that you always run the latest Skype version: Windows & Mac
    If my advice helped to fix your issue please mark it as a solution to help others.
    Please note that I generally don't respond to unsolicited Private Messages. Thank you.

  • I have two iphone one is iphone 5 and othere is iphone 4 . can i use same id for both ? And do i have to purchase the application again for iphone 4 which i have buyed for iphone 5.??

    i have two iphone one is iphone 5 and othere is iphone 4 . can i use same id for both ? And do i have to purchase the application again for iphone 4 which i have buyed for iphone 5.??

    You can use the same Apple ID for both phones, you would then be able to use the purchased Apps/Content on both phones without having to pay again.

Maybe you are looking for

  • Schedule lines not getting confirmed on staurdays and sundays

    Hi all, At sales order level, the schedule lines are not getting confimred on staurdays and sundays. So,in the factory which has been assigned to that plant, we have checked all holidays . Even then it's not confirming on saturdaus and sundays. In th

  • More of a report than a question. Resently I have had a dialog box appear warning me that an unauthorized up date has been denied.r warning

    recently I have received a dialog box warning that an unauthorized update to Firefox has been blocked. There are instructions to notify my administrator. I have been having trouble over the past few days with the RX rate being very low and stopping.

  • 10.1.3.5 BpelConsole question

    Hi all After upgrade to 10.1.3.5 SoaSuite I have found some changes in BpelConsole. Now HumanTask in flow of Bpel process show as scope. I older version I was able to click on HumanTask and see Assigner, StartDate and etc. Now it's unavailable. Does

  • White frame in JPG export

    If I choose at AI, the export, to jpg option, and tick the use artboards option, the exported jpg will get a rather thick white frame. The document has no stroke, if i export without the use artboard option there is no problem.... any suggestion?

  • Verizon Outgoing Spam Detector is Seriously Flawed

    Several times in the past few months I've tried to respond to emails to me with simple, one or two line comments. This has been done from Outlook. In each case Verizon bounced my email as being spam. Absolute nonsense. I sent the email as per their S