Simple TCP/IP

I have a program which I would like to interface with a router using TCP/ip protocol. Ideally the program should notify the router that it is ready to receive current data. (500 bits consisting of some instrument readings)
Here is related part of program
urlString=prompt("Type a URL address");
               URL urlAddress=new URL(urlString);
               URLConnection link=urlAddress.openConnection();
Now the main question is can I use formatting in the URL address which i type in such that it will do this interface? Or do I need to build support software which I am unaware of?
Thank you for you time and help.

System.out.print(getProtocol(urlAddress));
cannot resolve symbol symbol: method getProtocol <java.net.URL>
location class Tcp
System.out.print(getProtocol(urlAddress));
^
Well, I'm trying to find right way to say I want to do TCP format. This is using a method of accepting urlAddresses that has worked, but when I added this line now doesn't compile.
*I'm trying to do TCP/IP, and I have a program that reads http format, and don't know what additional coding/ information I need to specify to answer your question.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Help with java.util.logging SocketHandler - Simple TCP Server

    I have a simple TCP serverString clientSentence;
                 ServerSocket welcomeSocket = new ServerSocket(5050);
                 while(true) {
                    Socket connectionSocket = welcomeSocket.accept();
                    BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                    while ((clientSentence = inFromClient.readLine()) != null) {
                         System.out.println("Received: " + clientSentence);
                 }And I have a java.util.logging logger using a SocketHandler. I'm just calling logger.log("my message"); I get the expected result to System.out: "my message". But when I go on to call again logger.log("my next message") I get both messages in queue: "my message" and "my next message" on the next line. So, I get from these two calls to logger.log() the following result in System.out
    my message
    my message
    my next message...whereas I expected
    my message
    my next messageWhy is "my message" being saved even after being passed through the TCP connection to the server? I tried handler.flush() but that doesn't help. Pretty sure the problem isn't at the server end because when I create two loggers with their own SocketHandlers the server doesn't double up on their messages. (In other words, if I let one logger say simply "my message" and the second logger say "my next message" I get the expected output. It's like each logger needs to be flushed after sending to the server.
    Any advice appreciated.

    Yes, I was just rereading your post and it's apparent that you were suspecting the client code. Your posting only the server led me to believe that you were focusing on that and I kind of skipped over the last part.
    So to answer your question, yes, the server code looks okay. And you were suspecting the client anyway, so problem solved.

  • How to program the simple tcp/ip connection?

    I would like to know how to program in labview the simple tcp/ip connetion.
    And is there some site with examples.

    Luciano Kan Horiuchi wrote:
    > I would like to know how to program in labview the simple tcp/ip connetion.
    > And is there some site with examples.
    You should probably start with the examples that ship with LabVIEW. For a good
    server-to-single-client example, check out Data Client.vi and Data Server.vi
    from the shipping examples, and for a good server-to-multiple-client example,
    try the Date Client.vi/Date Server.vi pair instead. All of these can be found
    in the following VI library:
    \examples\comm\tcpex.llb
    or via the Search Examples interface in LabVIEW. There are certainly
    additional examples on the NI site, but there's no better place to start than
    with these.
    Regards,
    John Lum

  • Simple tcp messaging vs. shared variable

    I am getting ready to deploy a project which will have one HMI and three sbRIOs on a closed local network with static IP addresses. Of course these devices will need to comminucate certain information to each other in order to advance the process each is responsible for. I have used shared variables back in LabVIEW 7.1 but not since. As I remember it was pretty straight forward and simple to implement. The data I will be sending will either be boolean or string. I was recently introducted to simple TCP messaging and was curious, based on experience, what will be the best option for reliable communication. i know this is potentially a vague question, but thanks anyway.
    Doug Ferguson
    www.southerndaqsolutions.com

    Hi Doug,
    Shared variables where introduced with LV8.0 so I don't think you used them with 7.1
    If you need to pass big amounts of data and lots of different types I would suggest to use STM, which is btw very easy to implement and allready gives a good example on communicating between more cRIOs and a Host.
    The advantage of Shared Variables is that they are very easy to implement, but for large data TCP/IP and so STM has a better performance.
    Christian

  • A simple tcp or udp example for ARM embedded

    I purchased the embedded ARM for the EK-LM3S8962 board. Could someone point me to a simple example to run a udp or tcp client on the ARM?
    thanks,
    Bill

    Hello Bill,
    We have a shipping example that will show you how to use your LM3S8962 board as a TCP client or server. You can find this example by navigating from the Menu Bar Help»Find Examples... Once the dialog box opens go to Toolkits and Modules»ARM»Luminary Micro»Protocol Drivers»TCP.lvproj.
    This example should be enough to get you started. Be sure to let us know if you have any additional questions.
    Stephanie
    Applications Engineering
    National Instruments

  • Simple TCP chat application half duplex not working for me

    I m having a problem in TCP application working half duplex
    My friend runs client program who is in near by city and i run the server program in my system
    Let my ip address is 116.x.y.z
    My server program is
    import java.net.*;
         import java.io.*;
         public class tcpserver
             public static void main(String args[]) throws IOException
              ServerSocket s1=null;
              try
                 s1=new ServerSocket(98);
              catch(IOException e)
                 System.err.println("Could not find port 98");
                 System.exit(1);
              Socket c=null;
              try
                 c=s1.accept();
                 System.out.println("Connection from"+c);
                                      catch(IOException e)
                 System.out.println("Accept failed");
                 System.exit(1);
              PrintWriter out=new PrintWriter(c.getOutputStream(),true);
              BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
              System.out.println("I am ready,type now");
              String l=in.readLine();
              while(l!=null)
                 out.println(l);
              out.close();
              in.close();
              c.close();
              s1.close();
         }The Client program is which my friend executes is
    import java.net.*;
         import java.io.*;
         public class tcpclient
             public static void main(String arg[]) throws IOException
              Socket s=null;
              BufferedReader b=null;
              try
                 s=new Socket(InetAddress.getByName("116.x.y.z"),98);
                 b=new BufferedReader(new InputStreamReader(s.getInputStream()));
              catch(UnknownHostException u)
                 System.err.println("I dont know host");
                 System.exit(0);
              String inp;
              while((inp=b.readLine())!=null)
                 System.out.println(inp);
                 break;
              b.close();
              s.close();
         }Important Note: When i run this program specifying within my system its working ( i mean running the program in two different windows(terminals) its working for me)
    When i give the client program to my friend its getting compiling for him but not running for him
    Its showing him unknownhost exception and main method not found like this.
    Please correct the above code or else just what kind of strategy we should follow in order to get rid of this problem
    When i normally run this program in my system
    the output when i run in my own system is
    Output for running tcpserver.java
    ~\JDK2~1.0\bin>java tcpserver
    Connection fromSocket[addr=/116.x.y.z,port=1930,localport=98] // in output i edit the ip address text
    I am ready,type now
    this is test text
    Output for running tcpclient.java
    ~\JDK2~1.0\bin>java tcpclient
    this is test text
    My problem is its working in my system when it exceeds out the output is not available for me
    Help me Please !!!

              String l=in.readLine();
              while(l!=null)
              out.println(l);
              }That will print the same thing forever. Make it the same as the loop in the client.
    Important Note: When i run this program specifying within my system its working ( i mean running the program in two different windows(terminals) its working for me)Looping forever might be what you call 'working'. I don't.
    Its showing him unknownhost exception and main method not found like this.Change this:
    new Socket(InetAddress.getByName("116.x.y.z"),98)to this:
    new Socket("116.x.y.z",98)although your friend may then run into connectivity problems ...

  • Simple TCP Client Program Problems

    The Code:
    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));
              Socket clientSocket = new Socket("www.utm.edu", 80);
              DataOutputStream outToServer = new DataOutputStream(
                   clientSocket.getOutputStream());
              BufferedReader inFromServer =
                   new BufferedReader(new InputStreamReader(
                        clientSocket.getInputStream()));
              sentence = inFromUser.readLine();
              outToServer.writeBytes(sentence + "\r\n");
              modifiedSentence = inFromServer.readLine();
              System.out.println("FROM SERVER: " +
                                       modifiedSentence);
              clientSocket.close();
    So...when the program loads the console...I type
    GET /staff/bbradley/200640/cs360/test1.txt
    And I'm supposed to get what's at the URL:
    http://www.utm.edu/staff/bbradley/200640/cs360/test1.txt
    But Instead I just get the first line of the text...any ideas?

    Change the code to
    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));
    Socket clientSocket = new Socket("www.utm.edu", 80);
    DataOutputStream outToServer = new DataOutputStream(
    clientSocket.getOutputStream());
    BufferedReader inFromServer =
    new BufferedReader(new InputStreamReader(
    clientSocket.getInputStream()));
    sentence = inFromUser.readLine();
    outToServer.writeBytes(sentence + "\r\n");
    modifiedSentence = inFromServer.readLine();
    while(modifiedSentence!=null)
    System.out.println("FROM SERVER: " +
    modifiedSentence);
    modifiedSentence = inFromServer.readLine();
    clientSocket.close();
    }

  • Simple TCP Chat program behid router

    Hello, I've been reading some of the examples from http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html, and understand how these examples work well enough to fool around with it...
    I have it working inside my local network (behind a router), but when I try to have someone from outside my network connect to my server, they are unable to connect. I used IPchicken to determine which IP to give them.
    What do I need to do to get this working behind routers?
    Thanks for any time taken.

    DeshBanks wrote:
    I figured it out, it looks like.
    I had to login to my router and configure virtual routing (or something like that - I think it is basically port forwarding) on a specific port to my machine on the private network. I then had to 'allow' this port in my firewall.Hence my advice in reply 1 to google for port forwarding and check out your router's manual.

  • Simple TCP

    I keep getting:
    IOException: java.net.SocketException: Software caused connection abort: socket write error
    when I use the code below.
    I've mixtred with it a bit ( now it sends diffrent commands than before) but I don't know what's causing the error.
    I already have a server that should respond correctly to this so I don't think it's the servers fault... And the server is the machine Im writing the code on... and the port is correct.
    Any Ideas?
    import java.io.*;
    import java.net.*;
    public class smtpClient {
    public static void main(String[] args) {
    // declaration section:
    // smtpClient: our client socket
    // os: output stream
    // is: input stream
    Socket smtpSocket = null;
    DataOutputStream os = null;
    DataInputStream is = null;
    // Initialization section:
    // Try to open a socket on port 25
    // Try to open input and output streams
    try {
    smtpSocket = new Socket("localhost", 56667);
    os = new DataOutputStream(smtpSocket.getOutputStream());
    is = new DataInputStream(smtpSocket.getInputStream());
    } catch (UnknownHostException e) {
    System.err.println("Don't know about host: hostname");
    } catch (IOException e) {
    System.err.println("Couldn't get I/O for the connection to: hostname" +e);
    // If everything has been initialized then we want to write some data
    // to the socket we have opened a connection to on port 25
    if (smtpSocket != null && os != null && is != null) {
    try {
    // The capital string before each colon has a special meaning to SMTP
    // you may want to read the SMTP specification, RFC1822/3
    os.writeBytes("ID|hello\n");
    os.writeBytes("QUERY|");
    // keep on reading from/to the socket till we receive the "Ok" from SMTP,
    // once we received that then we want to break.
    String responseLine;
    while ((responseLine = is.readLine()) != null) {
    System.out.println("Server: " + responseLine);
    if (responseLine.indexOf("Ok") != -1) {
    break;
    // clean up:
    // close the output stream
    // close the input stream
    // close the socket
    os.close();
    is.close();
    smtpSocket.close();
    } catch (UnknownHostException e) {
    System.err.println("Trying to connect to unknown host: " + e);
    } catch (IOException e) {
    System.err.println("IOException: " + e);

    I know the reason know...
    I sent two commands but the connection was closed after the first command...

  • Receive data through TCP connection

    Hi
    I'm receiving a string "Hello" from TCP from a C-program, where I have to display this string in a string indicator in LabVIEW. 
    I have the following block diagram I found among the examples: 
    The point here is that I can only read the last character "o" in the indicator when I change the "bytes to read" value to 4 bytes, but can read the characters "ello" when setting the bytes to read value to 1. How do I read the whole "Hello" string ?. 
    Best regards
    Oesen
    Attachments:
    Simple TCP - Client.vi ‏15 KB

    Since you are sending a string, I would try using "CLRN" mode on TCP Read.  Then you can trigger it to read all the text until the "/r/n" characters in C.
    mode indicates the behavior of the read operation.
    0
    Standard (default)—Waits until all bytes you specify in bytes to read arrive or until timeout ms runs out. Returns the number of bytes read so far. If fewer bytes than the number of bytes you requested arrive, returns the partial number of bytes and reports a timeout error.
    1
    Buffered—Waits until all bytes you specify in bytes to read arrive or until timeout ms runs out. If fewer bytes than the number you requested arrive, returns no bytes and reports a timeout error.
    2
    CRLF—Waits until all bytes you specify in bytes to read arrive or until the function receives a CR (carriage return) followed by a LF (linefeed) within the number of bytes you specify in bytes to read or until timeout ms runs out. The function returns the bytes up to and including the CR and LF if it finds them in the string.
    3
    Immediate—Waits until the function receives any bytes from those you specify in bytes to read. Waits the full timeout only if the function receives no bytes. Returns the number of bytes so far. Reports a timeout error if the function receives no bytes.
    Otherwise, you need to follow the instructions per protocol;
    bytes to readis the number of bytes to read. Use one of the following techniques to handle messages that might vary in size:
    Send messages that are preceded by a fixed size header that describes the message. For example, it might contain a command integer that identifies what kind of message follows and a length integer that identifies how much more data is in the message. Both the server and client receive messages by issuing a read function of eight bytes (assuming each is a four byte integer), converting them into the two integers, and using the length integer to determine the number of bytes to pass to a second read function for the remainder of the message. Once this second read is complete, each side loops back to the read function of the eight byte header. This technique is the most flexible, but it requires two reads to receive each message. In practice, the second read usually completes immediately if the message is written with a single write function.
    Make each message a fixed size. When the content of a message is smaller than the fixed size you specify, pad the message to the fixed size. This technique is marginally more efficient because only a single read is required to receive a message at the expense of sending unnecessary data sometimes.
    Send messages that are strictly ASCII in content, where each message is terminated by a carriage return and linefeed pair of characters. The read function has a mode input that, when passed CRLF, causes it to read until seeing a carriage return and linefeed sequence. This technique becomes more complicated when message data can possibly contain CRLF sequences, but it is quite common among many internet protocols, including POP3, FTP, and HTTP.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • TCP communicat​ion temporaril​y dies

    Hi There
    Im using TCP to communicate between my ARM processor and PC. However, the communication sporadically dies for 3 to 4 seconds and then resumes, as shown in the Task Manager Networking (attachment 1) . This happens with the simplest of test programs, as shown in the attachments, and no delays or sequences seemed to solve the issue. 
    After some duration the communication dies completely with error code 66.
    What is causing the delays in communication and is there a fix for this?
    Attachments:
    simple TCP failure.jpg ‏527 KB
    Simple Server - ARM.jpg ‏72 KB
    Simple Client - PC.jpg ‏74 KB

    Hey,
    What kind of delay did you add into the VI?  it sounds like a pretty classic case of reading and writing TCP too fast.  You may want to take a look at this article: http://digital.ni.com/public.nsf/allkb/4CB799F36D0​EA56A862576200064B2F9?OpenDocument
    Regards,
    Eric L.
    Applications Engineer
    National Instruments

  • Problem regarding the transmission of video Through TCP/IP acquired from USB camera

    I want to transmit video using TCP/IP protocol acquired from USB camera. Acquisition is done well but when I place the TCP VIs in the acquisition VI then the trouble begins and I can’t even get the video in that particular VI which was acquiring video and working fine previously.
    Interesting thing is that both Cam Server and Cam Client VIs was transmitting video in the very first run. After that I don’t know what happened.
    I am using lab view 8.2.1.VIs are attached.
     Please help me out.
    Regard,
    Aftab
    Attachments:
    Cam client.vi ‏49 KB
    Cam Server.vi ‏67 KB
    camera.zip ‏66 KB

    Hi Shoaib,
    Here's an example I was testing mixing IMAQdx and the Simple TCP/IP Messaging Protocol (http://zone.ni.com/devzone/cda/tut/p/id/4095) to send up a video client/server app with a USB camera that I was testing with.
    Attachments:
    video client.vi ‏41 KB
    video server.vi ‏22 KB

  • TCP IP question

    Hi everyone,
    I would like to try a very simple TCP/IP connection.
    In other words, I have to IP addresses, two PC and on one of it, I would like to read the temperature captured by the other.
    Since it's a large topic, I would appreciate any advice or suggestion on where to find examples.
    Thanks in advance
    Gérard
    Gérard Férini
    Switzerland
    http://home.tiscalinet.ch/gferini/Main_Photos.html

    Thanks Dan for your reply
    Gérard
    Gérard Férini
    Switzerland
    http://home.tiscalinet.ch/gferini/Main_Photos.html
    "dan bookwalter" wrote in message
    news:[email protected]..
    > Gerard
    >
    > start by looking at the Simple Data Client.vi and Simple Data
    > Server.vi examples that ship with LabVIEW... that should get you
    > started...
    >
    > Dan

  • Send multiple strings over TCP - Like messenger service

    Hello all Java Coders,
    I'm new with TCP programming.
    I'm beggining to learn about TCP and sockets connections in Java. In order to achieve this, I was coding a mini-program so I can learn a little bit about this.
    I'm trying to make a simple TCP program.
    The server sends a string to a client...
    I already searched for a couple of hours in google and so on, about what I'm doing wrong.
    [The server code (Just click)|http://pastebin.com/m39fd1273]
    [The client code (Just click)|http://pastebin.com/m57471803]
    I hope that someone can help me with this and, if you have patience, please tell me the reasons my code doesn't work.
    Many thanks,
    Freiheitpt
    P.S.: I think that the problem is on the server side...

    Sorry jverd.
    I was just trying to put things organized.
    Well, I can't get the String to be sent to the client.
    No error occurs.
    Server:
           try {
                srvr = new ServerSocket(1234);
                System.out.println("Connecting...");
                skt = srvr.accept();
                System.out.println("Connected!\nPreparing data exchange...");
                stream = skt.getOutputStream();
                out = new PrintWriter(stream, true);
                System.out.println("Done!\nReady to Send!");
            } catch (IOException ex) {
                System.out.println("Ups, didn't work!");
                System.exit(1);
            while(!data.equalsIgnoreCase("end")) {
                System.out.print("String to send: ");
                data = input.nextLine();
                System.out.print("Sending string: '" + data + "'\n");
                out.print(data);
            }Client:
            try {
                skt = new Socket("localhost", 1234);
                System.out.println("Connecting...");
                if (skt.isConnected()) {
                    System.out.println("Connected!\nPreparing data exchange...");
                    stream = skt.getInputStream();
                    inputStream = new InputStreamReader(stream);
                    in = new BufferedReader(inputStream);
                    System.out.println("Done!\nReady to Receive!");
                } else {
                    System.out.println("Server not available!\nExiting...");
                    skt.close();
                    System.exit(1);
            } catch (IOException ex) {
                System.out.println("Ups, didn't work!");
                System.exit(1);
            while (!data.equalsIgnoreCase("end")) {
                while(!in.ready()) {}
                data = in.readLine();
                System.out.println("Received String: '" + data + "'");
            }

  • TCP client server sample

    All,
    This may not really be a LabWindows/CVI question but I'm really stuck on what should be easy to
    solve. The brain trust here on the forums has always been helpful so I'll try to explain.
    The project:
    Get LabWindows/CVI code talking to a muRata SN8200 embedded WiFi module.
    The setup:
    (running Labwindows/CVI 2009)
    Computer 1 -- (with a wireless NiC) running simple demo TCP server program provided by muRata.
    Computer 2 -- USB connection (virtual COM port) with simple program (also provided by muRata) that talks to the SN8200 embedded WiFi module.  This code along with the module creates a simple TCP client.
    Whats working:
    I can successfuly get the Computer 2 client connected to and talking to the Computer 1 server. (using the muRata supplied code)
    I can also run the LabWindows/CVI sample code from (\CVI2009\samples\tcp), server on computer 1 & client on computer 2 and they talk with no problems.
    (I'm using the same IP addresses and port numbers in all cases)
    Whats NOT working:
    Run the CVI server program on computer 1.
    I cannot get the muRata client program  to connect to the CVI server.
    I also tried get the CVI client program to connect to the muRata server.  No luck that way either. The CVI client sample program trys connect, and this function call:
    ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000 );
    returns with a timeout error code (-11).
    What I need:
    Some ideas on how to get this working.
    Is there something unique about the LabWindows/CVI sample client/server demo code that would make them incompatible with the muRata code?
    Can you think of some ways I can debug this further?  I feel like I'm kind of running blind.
    What else can I look at?
    For those that have read this far, thanks much and any ideas or comments will be appreciated,
    Kirk

    Humphrey,
    First,
    I just figured out what the problem is:
    When I was trying to use the CVI sample server I was entering the wrong port number.
    The reason I entered the wrong port was because the hard-coded port number in the muRata demo code was displayed in hex as 0x9069. ( I converted this to decimal and entered it into the CVI sample server code) The correct port number was 0x6990.  (upper and lower bytes swapped)  Arrgh!
    I found the problem by using the netstat command line utility to display the connections and noted that the port being used was not 0x9069.  It is really a problem with the muRata eval kit demo code.
    Second,
    Humphrey you are right about the CVI sample code not handling all the muRata commands for the client end of the connection that communicates with the SN8200 module.  For my test I was using the muRata code for that "end".
    The server end is simple and the CVI sample is adequate and is now working.
    Thank you to all who took the time to browse my questions,
    Kirk

Maybe you are looking for