TCP client server

hi,
how do i do this:
Create a Server Program in TCP
Create a file with some data.
Create a Client Program in TCP
Establish a connection with the server
On establishment, the server should read the data from the file and write onto the socket of the client.
The client has to read the data from the socket and write onto a different file.

hi,
this is the server code that i have.
import java.io.*;
import java.net.*;
public class fileServer {
public fileServer() {
int i=1;
try {
ServerSocket s = new ServerSocket(5000);
System.out.println("Server Started...");
Socket incoming = s.accept();
Thread t = new ThreadedServer(incoming, i);
i++;
t.start();
}catch(Exception e){
System.out.println("Error: "+e);
public static void main(String args[]){
new fileServer();
class ThreadedServer extends Thread{
int n;
Socket fileSocket;
int count;
public ThreadedServer(Socket i, int c){
fileSocket = i;
count = c;
public void run(){
BufferedReader buffRead = null;
OutputStream os;
try{
File f = new File("file1.txt");
FileInputStream fis = new FileInputStream(f);
os = fileSocket.getOutputStream();
int buffSize = 4096;
byte[] buff = new byte[buffSize];
int count = 0;
while((count = fis.read(buff))>= 0) {
os.write(buff,0,(int)count);
System.out.println(os);
fis.close();
os.close();
}catch(IOException ioe) {
System.out.println("this is a IOException"+ioe.getMessage());
This is the client code that i have:
import java.io.*;
import java.net.*;
public class fileClient{
public static void main(String args[]){
Socket clientSocket;
PrintStream out = null;
BufferedReader in = null;
try{
clientSocket = new Socket("10.45.2.34",5000);
System.out.println("connection established");
out = new PrintStream(clientSocket.getOutputStream());
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String text = in.readLine();
System.out.println(text);
in.close();
out.close();
}catch (UnknownHostException e){
System.err.println("unidentified hostname");
System.exit(1);
}catch(IOException ioe) {
System.err.println("couldnt get I/O");
System.exit(1);
The above code works fine,but the final step i.e the client has to read the data from the socket and write onto a different file is not performed.
So how do i proceed from here.

Similar Messages

  • Help with MIDlets - TCP client server program

    Hi I am new to using MIDlets, and I wanted to create a simple TCP client server program.. I found a tutorial in J2me forums and I am able to send a single message from server(PC) to client(Phonemulator) and from client to server. But I want to send a stream of messages to the server. Here is my program and I am stuck in the last step wher i want to send lot of messages to server. Here is my program, Could any one of u tell me how to do it? Or where am i going wrong in thsi pgm?
    Code:
    import java.io.InputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.SocketConnection;
    import javax.microedition.io.StreamConnection;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.StringItem;
    import javax.microedition.lcdui.TextField;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeExcepti on;
    public class SocketMIDlet extends MIDlet
    implements CommandListener, Runnable {
    private Display display;
    private Form addressForm;
    private Form connectForm;
    private Form displayForm;
    private TextField serverName;
    private TextField serverPort;
    private StringItem messageLabel;
    private StringItem errorLabel;
    private Command okCommand;
    private Command exitCommand;
    private Command backCommand;
    protected void startApp() throws MIDletStateChangeException {
    if (display == null) {
    initialize();
    display.setCurrent(addressForm);
    protected void pauseApp() {
    protected void destroyApp(boolean unconditional)
    throws MIDletStateChangeException {
    public void commandAction(Command cmd, Displayable d) {
    if (cmd == okCommand) {
    Thread t = new Thread(this);
    t.start();
    display.setCurrent(connectForm);
    } else if (cmd == backCommand) {
    display.setCurrent(addressForm);
    } else if (cmd == exitCommand) {
    try {
    destroyApp(true);
    } catch (MIDletStateChangeException ex) {
    notifyDestroyed();
    public void run() {
    InputStream is = null;
    OutputStream os = null;
    StreamConnection socket = null;
    try {
    String server = serverName.getString();
    String port = serverPort.getString();
    String name = "socket://" + server + ":" + port;
    socket = (StreamConnection)Connector.open(name, Connector.READ_WRITE);
    } catch (Exception ex) {
    Alert alert = new Alert("Invalid Address",
    "The supplied address is invalid\n" +
    "Please correct it and try again.", null,
    AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, addressForm);
    return;
    try {
    // Send a message to the server
    String request = "Hello\n\n";
    //StringBuffer b = new StringBuffer();
    os = socket.openOutputStream();
    //for (int i=0;i<10;i++)
    os.write(request.getBytes());
    os.close();
    // Read the server's reply, up to a maximum
    // of 128 bytes.
    is = socket.openInputStream();
    final int MAX_LENGTH = 128;
    byte[] buf = new byte[MAX_LENGTH];
    int total = 0;
    while (total<=5)
    int count = is.read(buf, total, MAX_LENGTH - total);
    if (count < 0)
    break;
    total += count;
    is.close();
    String reply = new String(buf, 0, total);
    messageLabel.setText(reply);
    socket.close();
    display.setCurrent(displayForm);
    } catch (IOException ex) {
    Alert alert = new Alert("I/O Error",
    "An error occurred while communicating with the server.",
    null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    display.setCurrent(alert, addressForm);
    return;
    } finally {
    // Close open streams and the socket
    try {
    if (is != null) {
    is.close();
    is = null;
    } catch (IOException ex1) {
    try {
    if (os != null) {
    os.close();
    os = null;
    } catch (IOException ex1) {
    try {
    if (socket != null) {
    socket.close();
    socket = null;
    } catch (IOException ex1) {
    private void initialize() {
    display = Display.getDisplay(this);
    // Commands
    exitCommand = new Command("Exit", Command.EXIT, 0);
    okCommand = new Command("OK", Command.OK, 0);
    backCommand = new Command("Back", Command.BACK, 0);
    // The address form
    addressForm = new Form("Socket Client");
    serverName = new TextField("Server name:", "", 256, TextField.ANY);
    serverPort = new TextField("Server port:", "", 8, TextField.NUMERIC);
    addressForm.append(serverName);
    addressForm.append(serverPort);
    addressForm.addCommand(okCommand);
    addressForm.addCommand(exitCommand);
    addressForm.setCommandListener(this);
    // The connect form
    connectForm = new Form("Connecting");
    messageLabel = new StringItem(null, "Connecting...\nPlease wait.");
    connectForm.append(messageLabel);
    connectForm.addCommand(backCommand);
    connectForm.setCommandListener(this);
    // The display form
    displayForm = new Form("Server Reply");
    messageLabel = new StringItem(null, null);
    displayForm.append(messageLabel);
    displayForm.addCommand(backCommand);
    displayForm.setCommandListener(this);

    Hello all,
    I was wondering if someone found a solution to this..I would really appreciate it if u could post one...Thanks a lot..Cheerz

  • TCP Client - Server Prog.

    Hi All,
    I have posted TCP client- server prog. I have trouble in client code. When i'm running the server code on some port and the running the client code on the same port, then client is sending message to server(in this case integers with space like 12 22 23) , the server is receiving the message and adding the sum and sending the sum to client, but when i'm trying to read the stream from server(i.e the sum), i'm getting nothing.........
    please run the code and check.......u can understand well....
    please reply me as soon as possible.
    Thanks
    import java.io.*;
    import java.net.*;
    class TCPAdditionClient
         public static void main(String args[]) throws Exception
         {   Character ans = null;
              String hostname="localhost";
              String sentence;
              String result;
              int port=0;
              if (args.length > 0) {
              try {
              port = Integer.parseInt(args[0]);
              } catch (NumberFormatException e) {
              System.err.println("Argument must be an integer");
              System.exit(1);
              Socket clientSocket = new Socket(hostname,port);
              do
                   System.out.println("Enter the number of integers....");
                   BufferedReader fromUser = new BufferedReader(new InputStreamReader(System.in));
                   sentence = fromUser.readLine();
                   DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
                   //System.in.read();
                   outToServer.writeBytes(sentence + '\n');
                   System.out.println("server sends message");
                   BufferedReader fromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                   System.out.println(fromServer);
                   result = fromServer.readLine();
                   System.out.println("from Server" + result);
                   System.out.println("Do u want to continue y/n");
              }while(! ans.equals("n"));
              clientSocket.close();
    import java.io.*;
    import java.util.*;
    import java.net.*;
    class TCPAdditionServer
         public static void main(String args[]) throws Exception
              String clientSentence;
              int port=0;
              if (args.length > 0) {
              try {
              port = Integer.parseInt(args[0]);
              } catch (NumberFormatException e) {
              System.err.println("Argument must be an integer");
              System.exit(1);
              ServerSocket welcomeSocket = new ServerSocket(port);
              while(true)
                   int sum = 0,total_sum = 0;
                   Socket connectionSocket = welcomeSocket.accept();
                   BufferedReader fromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                   DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
                   clientSentence = fromClient.readLine();
                   System.out.println(clientSentence);
                   String[] result = clientSentence.split(" ");
                   for (int x=0; x<result.length; x++)
                        sum = Integer.parseInt(result[x]);
                        total_sum = sum + total_sum;
                        System.out.println(total_sum);
                   String sendData = "from the server" + "sum :" + total_sum;
                   System.out.println(sendData);
                   outToClient.writeBytes(sendData);
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    can u explain it http://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal - in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • 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

  • TCP Client Server - how to set timeout and bandwidth option

    Hi Friends,
    I am writing a simple TCP based client-server app and I would like the connection to be dropped after a certain time of inactivity and also I would like to control the connection's bandwidth. I would appreciate if someone can throw some pointers as to how this can be done.
    I have tried this so far, for Timeout I am trying to do this:
    sock.setSoTimeout(10000);But I think this is not the right way as this will disconnect the server from all client connections I guess. I think the better way would be to write a timer or something for each connection but I don't know how...
    Any help?

    Micks80 wrote:
    Hi Friends,
    I am writing a simple TCP based client-server app and I would like the connection to be dropped after a certain time of inactivity and also I would like to control the connection's bandwidth. I would appreciate if someone can throw some pointers as to how this can be done.
    I have tried this so far, for Timeout I am trying to do this:
    sock.setSoTimeout(10000);But I think this is not the right way as this will disconnect the server from all client connections I guess.Wrong in a couple of ways.
    1) That doesn`t disconnect anything. It causes a read that reaches that time in blocking to be unblocked and an exception (java.net.SocketTimeoutException) is thrown. The Socket is still just fine and can be used (all other things being equal). At any rate you then decide what you want to do after a timeout. One possibility is to close the socket because to you that timeout means it is abandoned.
    2) setSoTimeout of ServerSocket applies to the accept* method. setSoTimeout of Socket applies to reads from that sockets input stream. Neither of those apply anything to all connections.
    I think the better way would be to write a timer or something for each connection No setSoTimeout is correct. You will also then need to actually attempt to read something for that timeout exception to ever be thrown.
    As far as the bandwidth question goes, you will need to define your goals better. Please do not just restate "control bandwidth" because that is not actually a very specific goal. Do you want to limnit the bandwidth used at one time (tricky) or do you want to limit the total bandwidth used. Either way requires some work but they are different things.

  • TCP Client/Server Whiteboard - Like Netmeeting - Need advice

    I won't get into details of the full project, but one part of the project is a whiteboard-like VI that works similar to the whiteboard in Netmeeting. I created a quick server and client VI to establish a TCP connection to allow the whiteboard to run for everyone. Run the server VI first and then the client VI and the whiteboards will open. Normally you would only have one whiteboard running, but this is a demo to allow the client and server to run on the same computer. Please execute the project to understand what the program does so that you understand the concept.
    Now for my problem: I spent a several days designing this portion of my project and it is fairly usable, but the problem is that if you continuously draw on the screen for a long time (maybe 1 minute), the arrays will get rather large and will eventually slow the drawing process to a crawl. In a previous version I would draw to the screen, feedback the picture element, and then clear the array, thinking this would be the most efficient. Unfortunately it seemed to be pretty slow also.
    I've only been using Labview for a year, so please forgive me if my code is sloppy or if I did things in a weird way. This is why I am posting this code. I'm really looking for advice on optimizing the code and fixing my main problem.
    Attachments:
    Whiteboard.zip ‏413 KB

    Hi Travis,
    Thanks for your reply. I saw your post after I already solved the problem otherwise I would look into your suggestions. I thought I would post the solution here so that this code might help someone in the future.
    To recap, I had a problem with a drawing slowdown using two different methods. The first method was to draw to a picture element and then loop this around the main while loop and then draw to the picture element again for every pixel movement captured. Reloading the picture element rapidly was a major drag on the CPU. So the second method I used was to store all pixels movements captured in an array and add another array to the second dimension every time the mouse button lifted. I would draw EVERYTHING in this 2D array everytime I looped around. This meant that the array could get rather large after a very short time and bog down the CPU.
    So I realized that I could take the best of both methods mentioned and use a nested while loop inside another while loop. The outer while loop shifts the picture element around and the inner loop will continue to build and redraw only one row of the array until the mouse button is up. At this point I stop the inner loop and pass the picture element around null the arrays for the inner loop. Seems to accomplish everything I needed.
    Hope this can help somebody else. The new code is attached
    Attachments:
    Whiteboard.zip ‏515 KB

  • Async tcp client and server. How can I determine that the client or the server is no longer available?

    Hello. I would like to write async tcp client and server. I wrote this code but a have a problem, when I call the disconnect method on client or stop method on server. I can't identify that the client or the server is no longer connected.
    I thought I will get an exception if the client or the server is not available but this is not happening.
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    How can I determine that the client or the server is no longer available?
    Server
    public class Server
    private readonly Dictionary<IPEndPoint, TcpClient> clients = new Dictionary<IPEndPoint, TcpClient>();
    private readonly List<CancellationTokenSource> cancellationTokens = new List<CancellationTokenSource>();
    private TcpListener tcpListener;
    private bool isStarted;
    public event Action<string> NewMessage;
    public async Task Start(int port)
    this.tcpListener = TcpListener.Create(port);
    this.tcpListener.Start();
    this.isStarted = true;
    while (this.isStarted)
    var tcpClient = await this.tcpListener.AcceptTcpClientAsync();
    var cts = new CancellationTokenSource();
    this.cancellationTokens.Add(cts);
    await Task.Factory.StartNew(() => this.Process(cts.Token, tcpClient), cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
    public void Stop()
    this.isStarted = false;
    foreach (var cancellationTokenSource in this.cancellationTokens)
    cancellationTokenSource.Cancel();
    foreach (var tcpClient in this.clients.Values)
    tcpClient.GetStream().Close();
    tcpClient.Close();
    this.clients.Clear();
    public async Task SendMessage(string message, IPEndPoint endPoint)
    try
    var tcpClient = this.clients[endPoint];
    await this.Send(tcpClient.GetStream(), Encoding.ASCII.GetBytes(message));
    catch (Exception exception)
    private async Task Process(CancellationToken cancellationToken, TcpClient tcpClient)
    try
    var stream = tcpClient.GetStream();
    this.clients.Add((IPEndPoint)tcpClient.Client.RemoteEndPoint, tcpClient);
    while (!cancellationToken.IsCancellationRequested)
    var data = await this.Receive(stream);
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    private async Task Send(NetworkStream stream, byte[] buf)
    await stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
    await stream.WriteAsync(buf, 0, buf.Length);
    private async Task<byte[]> Receive(NetworkStream stream)
    var lengthBytes = new byte[4];
    await stream.ReadAsync(lengthBytes, 0, 4);
    var length = BitConverter.ToInt32(lengthBytes, 0);
    var buf = new byte[length];
    await stream.ReadAsync(buf, 0, buf.Length);
    return buf;
    Client
    public class Client
    private TcpClient tcpClient;
    private NetworkStream stream;
    public event Action<string> NewMessage;
    public async void Connect(string host, int port)
    try
    this.tcpClient = new TcpClient();
    await this.tcpClient.ConnectAsync(host, port);
    this.stream = this.tcpClient.GetStream();
    this.Process();
    catch (Exception exception)
    public void Disconnect()
    try
    this.stream.Close();
    this.tcpClient.Close();
    catch (Exception exception)
    public async void SendMessage(string message)
    try
    await this.Send(Encoding.ASCII.GetBytes(message));
    catch (Exception exception)
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.SafeInvoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    private async Task Send(byte[] buf)
    await this.stream.WriteAsync(BitConverter.GetBytes(buf.Length), 0, 4);
    await this.stream.WriteAsync(buf, 0, buf.Length);
    private async Task<byte[]> Receive()
    var lengthBytes = new byte[4];
    await this.stream.ReadAsync(lengthBytes, 0, 4);
    var length = BitConverter.ToInt32(lengthBytes, 0);
    var buf = new byte[length];
    await this.stream.ReadAsync(buf, 0, buf.Length);
    return buf;

    Hi,
    Have you debug these two applications? Does it go into the catch exception block when you close the client or the server?
    According to my test, it will throw an exception when the client or the server is closed, just log the exception message in the catch block and then you'll get it:
    private async void Process()
    try
    while (true)
    var data = await this.Receive();
    this.NewMessage.Invoke(Encoding.ASCII.GetString(data));
    catch (Exception exception)
    Console.WriteLine(exception.Message);
    Unable to read data from the transport connection: An existing   connection was forcibly closed by the remote host.
    By the way, I don't know what the SafeInvoke method is, it may be an extension method, right? I used Invoke instead to test it.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • TCP client communicating with UDP server

    Hello,
    I want to make a TCP client to communicate with an UDP server. Does anyone know a way of doing this? I am not interested in reliable data transfer. So I don't care if the datagram is lost. I want to make the UDP server accept some datagrams from the TCP client. Also, the datagram that I want to transmit is less than 65,536 octets so it is not devided to several datagrams. Therefore, only one exchange procedure occurs.
    I made an UDP server using DatagramSocket and DatagramPacket classes and a TCP client using Socket class, but the TCP client informs me that the connection was refused.
    Any ideas?

    Let's google for IP header and the first hit is http://www.networksorcery.com/enp/protocol/ip.htm (Whoa! Classic page! I must have seen that back when googling was called altavista.)
    There is a header field, a single byte, called protocol. For TCP/IP that field contains 6, for UDP/IP it contains 17.
    If you send a packet with protocol=17, the receiving host's kernel will check if it has an process listening to UDP (17) at the port specified in the packet header. No such process? Then simply discard the packet. So you can't send an UDP packet to a TCP socket because the protocol field is wrong.
    If you want to fake a TCP stream you could look into jpcap, which allows you to capture and send raw packets. Google for it; and pick the right jpcap, there are two, only one of which (AFAIK) can send packets. Attempting to write your own TCP implementation is highly advanced though, and not really practical.

  • Handle Received data of Multiple TCP clients on TCP Server by displaying them into Datagrid

    Hello All,
    I have developed a C# based TCP server GUI application which is accepting the data from multiple TCP clients on TCP server.
    The data i am receiving from TCP clients is a 32 bit data. In my application multiple TCP client data goes like this:
    00012331100025123000124510321562
    01112563110002512456012451032125 and so on...
    Now i want those data of the TCP clients to be parsed into 4 bits first and display it in 8 columns (32/4=8) of (say) datagrid as each 4 bit represents some characteristics of the TCP client. The same thing
    should work for next TCP client on second row of datagrid.            
    Can you give me some suggestion or an example how to go about this? Any help would be appreciated.
     Thank you in advance.
    Here is my code for receiving data from multiple TCP clients.
    void m_Terminal_MessageRecived(Socket socket, byte[] buffer)
    string message = ConvertBytesToString(buffer, buffer.Length);
    PublishMessage(listMessages, string.Format("Sockets: {0}", message));
    // Send Echo
    // m_ServerTerminal.DistributeMessage(buffer);
    private string ConvertBytesToString(byte[] bytes, int iRx)
    char[] chars = new char[iRx + 1];
    System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
    d.GetChars(bytes, 0, iRx, chars, 0);
    string szData = new string(chars);
    return szData;

    Now i want those data of the TCP clients to be parsed into 4 bits first and display it in 8 columns (32/4=8) of (say) datagrid as each 4 bit represents some characteristics of the TCP client. The same thing
    should work for next TCP client on second row of datagrid
    If mean it's a Windows Forms application and you want to display those bits in a DataGridView control, then please see these threads:
    Add row to datagridview
    Programmatically add new row to DataGridView
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Help needed on TCP/IP Multi-port Client-Server

    Hi all, I am trying to develop a client-server application to stream some data over a few random port numbers (defined by myself) to stream data over to the TCP server (i.e another computer) in LabVIEW. So far, I have created my application using the NI examples for "Simple Data Client + Server" and it works fine. I also understand that the "TCP Listen" VI is only able to listen for 1 TCP connection only and a way around this is to use queueing idea to receive & process the incoming data.The downside to the idea is that the "base port" (i.e initial port) needs to be the same (on every TCP client) with the TCP Server and it is not fit for the purpose I intended.
    Basically on the TCP server side, i need to chart/monitor the data on different port numbers that is being streamed real-time from the one TCP client computer. Is this possible in LabVIEW?
    Can anyone (incl. NI gurus) advise and point me in the right direction?
    *lost*
    Solved!
    Go to Solution.

    Hi
        http://zone.ni.com/devzone/cda/epd/p/id/2739 Here you can download that component.But you can also use TCP icons which is available in Data Commmunications>Protocals>TCp for communication and to read and write data use variant to flattened string. I have attached a small example where i will transfer a constant string to the host PC to check the link between client and the server. Hope this helps you.
    Attachments:
    TCP Comm.zip ‏47 KB

  • My Tcp/ip multi-client server is not passing the data string into the flatten to string vi

    I am using labview Multi-connection cleint and server to build my own multi-client server connection.
      The problem i am having is that the data does not get through the flatten to string vi. Would anyone be kind enough to tell me why is that happening? and what I do to fix it.
      Attached code . My goal is to send data to the client via tcp/ip and use the data to perform certain task.
      Thanks a whole lot
    Attachments:
    multiconnection-server.vi ‏39 KB
    multiconnection-client.vi ‏21 KB

    Instead, I decided to upload the code and recent mods I have made to it .
    see attached
    Attachments:
    multiconnection-clienttest.vi ‏43 KB
    multiconnection-servertest.vi ‏21 KB

  • Client-Server receive/send with TCP (high data rates)

    hello ,
    i want to test client -server one way throughput with TCP , any one can give me more hint about it ??

    Don't start a new thread if it's still about the same question.
    Especially when you add no new information.
    Show us the code you're currently using [in your original thread|http://forums.sun.com/thread.jspa?threadID=5434178&start=25].

  • Looking for a client/server that supports multiple protocol and delivery

    Hi all, I don't know if this the right place to ask my question,here it goes.
    I am looking to develop a client-server that supports multiple protocols such as HTTP, HTTPS etc. I am looking for a framework( i don't know if that is correct or I need some kind of web-service (soap etc)) that would manage connection, security etc. I would like to like to devote most of my time in developing business objects with multiple delivery mechanism such as sending serilized java objects, xml message or soap message, or in some case JMS message as well. So I need a client server that can come in via TCP/IP or HTTP or anyother industry standard protocol and I should be able to service him with pub/sub model and also request/response model as well.
    I don't know if I had explained what I need, I would like to know what technologies I should be evaluating and which direction I should be heading... Also the server I'm developing should be free of Java constraints if needed...
    Also this service is not webbased service as now but if need arises I should have a flexibilty to make them web enabled in future. Also I would like to work with open source webservers or appservers if I need

    Inxsible wrote:I installed i3 - along with the i3status - which I still have to figure out. I am liking what I see as of now. It reminds me of wmii -- when I used it way back when. However I do not like the title bar. I would much rather prefer a 1 px border around the focused window.
    "i3 was created because wmii, our favorite window manager at the time, didn't provide some features we wanted (multi-monitor done right, for example), had some bugs, didn't progress since quite some time and wasn't easy to hack at all (source code comments/documentation completely lacking). Still, we think the wmii developers and contributors did a great job. Thank you for inspiring us to create i3. "
    To change the border of the current client, you can use bn to use the normal border (including window title), bp to use a 1-pixel border (no window title) and bb to make the client borderless. There is also bt  which will toggle the different border styles.
    Examples:
    bindsym Mod1+t bn
    bindsym Mod1+y bp
    bindsym Mod1+u bb
    or put in your config file
    new_window bb
    from: http://i3.zekjur.net/docs/userguide.html (you probably already found that by now )

  • JMX Client/Server Classpath error

    Good morning,
    I have some aplication thats monitoring Websphere MQ queues.
    For this i'm use some MQ Jars, but its work fine.
    I have JMX Client/Server, for connect into MQ Server, my aplication use the MQ class MQConstants.
    My JMX connection work fine to. So, my problem is.
    When I try to invoke my aplication method
    mbsc.invoke(objectName, "execute", params, sig);
    ....the fallow errors appears
    javax.management.RuntimeErrorException: Error thrown in operation execute
         at com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.access$100(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.invoke(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
         at sun.rmi.transport.Transport$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.rmi.transport.Transport.serviceCall(Unknown Source)
         at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
         at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
         at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
         at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
         at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl_Stub.invoke(Unknown Source)
         at javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.invoke(RMIConnector.java:972)
         at br.com.flexvision.mq.FlexJMXClient.connectMBClient(FlexJMXClient.java:67)
         at br.com.flexvision.mq.FlexJMXClient.main(FlexJMXClient.java:101)
    Caused by: java.lang.NoClassDefFoundError: com/ibm/mq/constants/MQConstants
         at br.com.flexvision.mq.beans.FlexMQStatistics.processFieldsTypes(FlexMQStatistics.java:209)
         at br.com.flexvision.mq.beans.FlexMQStatistics.execute(FlexMQStatistics.java:30)
         at br.com.flexvision.mq.beans.FlexMQStatistics.execute(FlexMQStatistics.java:25)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.StandardMetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(Unknown Source)
         at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
         at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.doOperation(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.access$100(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(Unknown Source)
         at javax.management.remote.rmi.RMIConnectionImpl.invoke(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
         at sun.rmi.transport.Transport$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.rmi.transport.Transport.serviceCall(Unknown Source)
         at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
         at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)The most important line in this error is:
    Caused by: java.lang.NoClassDefFoundError: com/ibm/mq/constants/MQConstants
    Because this is de MQ jar that i need.
    I try to set this into server class path, but doesn't work.
    Somebody knows how i fix this?

    And your server has this FileObject class on its classpath, does it?

  • How to minimize Client-Server Round-trip in ADF Faces application ?

    Hi All,
    We have just finished POC on our prototype of ADF Faces + ADF BC application. The POC Emphasizes on Bandwidth requirement.
    After receing the result from the communication provider, including : TCP packets send, Bytes sent from/to server and number of Client-Server Round-Trip.
    There are several part of the application that Must be tuned for the application to run on acceptable performance.
    Here is some page/ function that should be tuned :
    - First page, ADF Read Only Table with two images and some buttons, cause 5 round-trip
    - ADF Dialog Returning Value (as LOV), cause 4 Round-trips
    - On ADF Form, press Commit button, cause 3 Round-trips.
    So the question is :
    1) How to reduce round-trips on ADF Faces application ?
    2) How to minimize the bytes send from / To server on a specific user action ?
    Please give me some recommendation..
    Thank you very much,
    xtanto

    Hi Frank and Steve,
    Thank you for your reply.
    Yes Frank, what I mean by Round-Trip is the traffic between Client and the Server. And Yes, we will use VSAT where the latency is 1 - 1.5 second, so that round-trip matters significantly.
    What I will do is :
    - use minimal skin and No image at all
    - don't use Dialog for LOV because it requires AutoSubmit there.
    - Use 'Apply-Changes' button to do server-side validation before Commit.
    Then do the POC / testing again.
    Thank you,
    xtanto

Maybe you are looking for

  • Can I Sync My iPod on Two Computers?

    I have two computers (Windows) with my account. My main one has a USB issue, so I upgraded to iOS5 on the other. Is there still a way to wirelessly sync to my main computer? My iPod is looking for the secondary computer and thus is not seeing my main

  • Songs on ipod, but not in itunes - HELP!

    Hey. So my computer got completely cleaned out... and everything was gone. But, my songs remained on my ipod. I've since reinstalled everything... but cannot get the songs OFF my ipod, ON to my computer. Any help? I don't want to lose them, but I wou

  • Some keys are typing alt characters. Help!!

    Hey guys, My Macbook's keyboard has been acting extremely funky this past week. The primary issue deals with the "h" typing "˙" (it doesn't help now that the key is hanging off one hinge. I accidentally chipped one of hinges in my cleaning attempt) a

  • Help with iBook G3 12" Logicboard problem

    Hello. I have a strange problem with an iBook G3 12" 600 MHz, maybe you can help me. this is the story A friend gave me what he called a "dead ibook" The first thing I noticed is that when I connect the AC adapter, the plug light (orange) turns on fo

  • How to make server behaviors repeat region vertical?

    I have done many "Server Behavior, Repeat Region" showing vertical list without any other setup, now I'm doing a new one and is showing horizontal which doesn't make any sense. Does anybody know why and how to fix this "bad behavior"?