Multiple input stream in one socket connection

Can we have multiple input streams for a java socket connection? It means that in a client/server application (creates using java socket), can we have multiple input streams for the client side program. For example, the input streams are to cater for the need of letting the user to chat and downloading some files from the chat partner at the same time. And do we need to use thread to create the multiple input streams like the case when we create a multithreaded server? Anyone out there who knows the solution please post it. Thanks in advance.

Can we have multiple input streams for a java socket
connection? It means that in a client/server
application (creates using java socket), can we have
multiple input streams for the client side program.
For example, the input streams are to cater for the
need of letting the user to chat and downloading some
files from the chat partner at the same time. And do
we need to use thread to create the multiple input
streams like the case when we create a multithreaded
server? Anyone out there who knows the solution please
post it. Thanks in advance.Ok im no expert here but this is what i learned:
a Socket can have only one InputStream (Socket.getInputStream()) and one OutputStream Socket.getOutputStream()). So you will have to create a way to make multiple Socket connections in your client program. And yes, you have to use threads for your server. if you dont the client will have to wait until the user before them is finished with the connection before being able to connect. I hope this helps you out. BTW please check out http://www.javabible.com. they have the book online now for free.
Joeyford1

Similar Messages

  • Getting continious stream  in one socket connection

    i want to make one socket connection with client and when client send more than one packet ( it can be continious or after some time - in byte stream) how i will be able to get those packet in interwal.
    please suggest

    then maybe you can help me out ejp
    ***server side****
    buffer.clear();
    buffer.put("return string".getBytes());
    buffer.flip();
    while (buffer.hasRemaining())
        socketChannel.write(b);
    ***client side****
    int line;
    byte[] mybyte=new byte[1024];
    while ((line=in.read(mybyte,0,mybyte.length))!=-1)
             System.out.write(mybyte,0,line);
    System.out.println("write finished");these are code snippets frm a client server prog i have.
    if i just do with the single while loop, my client will see the full return msg, but not the write finish output. its always waiting for the -1 eos.
    now, if i use what i said earlier, it works fine. could you kindly help me with this problem?

  • Open an input stream to a socket

    How many times I can open an input stream to a socket? If I create more than one an input stream to a socket, does this affect anything?
    Thanks.

    Generally low level classes do not have high level logic. Socket is a low level class, it's only logic is to connect you to something, and allow you to read and write to that thing (through the socket) using streams. Being able to connect multiple times or setting marks on your stream is a higher level of logic. Putting to much logic is low level classes tends to reduce re-useablility (making unmarkable streams markable as nothing to do with sockets and can be re-used upon any streams that do not support to be marked) and sometimes performances (having marks means having a buffer means having a potential big memory allocation in your Socket that you do not control).
    So in your case, since you are not really interested in re-connecting a socket, you should rather go for a wrapping InputStream that provides marking capabilities over the streams used by the socket class itself.
       Socket socket = getSocket();
       // this one does not support to be marked
       InputStream stream = socket.getInputStream();
       // but now it does :)
       stream = new BufferedInputStream( stream );

  • Multiple input streams

    hey folks newbie here
    i am designing a client server program
    with my client i want to send serialized objects & primitive types across the socket to the server
    is it possible to creat two output streams on the same socket i.e an ObjectOutputStream & a DataOutputStream on the same socket, i have tried this but get some errors so i don't think this is possible
    if not possible how would i be able to send both primitive types & serialized objects across the same socket

    Forget about the first person's post. He his correct, but it is not the solution used by most developers.
    Multiple Input Streams/Output Streams are easy to create. A better "management" deal would be like FTP - FTP uses two port, one for data and one for commands.
    Socket objectSocket = new Socket("www.object-server.com", objectPort);
    Socket dataSocket = new Socket("www.data-server.com", dataPort);
    The server should implement a class which represents the connection of both sockets as a single client. Somethig like this:
    public class Connection {
        Socket dataSocket;
        Socket objectSocket;
        public Connection(Socket s1) {
            dataSocket = s1;
        public void addObjectSocket(Socket s2) {
            objectSocket = s2;
    }You can then use this class (permission given to copy and use without license hereby granted) to manage the task.
    There are also many other ways of doing this. You can also apply multiple i/o streams to the same socket - but your server/client needs to know which data type is being sent or to which stream the data needs to be read from.
    Example: Client sends binary file to server (such as FTP)
    ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
    PrintWriter out2 = new PrintWriter(socket.getOutputStream());
    The code above will work, but data send in one stream will not show up in the other stream. The server does the reverse for the input > adding different InputStreams to the socket, but when data is sent from the client's object stream both of the server's streams (BufferedReader or other text-based input) and the object stream will receieve the file, so you need to communicate between the client and server which stream to read from/write to.
    Client: Send file via socket to server by means of ObjectOutputStream
    Note: You should not need to implement the try-catch logic when passing the argument of the socket - since it would throw that in the class which was calling the constructor, but you CAN implement it here as long as it is not handled in the calling class. If you do, the complier should throw an error saying that the exception would not be thrown at this point.

  • Parsing input stream from a socket

    Hi, i must read a byte stream from a socket. My problem is that i cannot determine when a stream ends because there are no terminator characters. I tried to use the read() method of BufferedReader class but it blocks when server statement ends. Is there a way to read the stream and answer to the server?
    Thanks,
    Andrea

    andmus wrote:
    Hi, i must read a byte stream from a socket. My problem is that i cannot determine when a stream ends because there are no terminator characters. I tried to use the read() method of BufferedReader class but it blocks when server statement ends. Is there a way to read the stream and answer to the server?
    If you're reading HTTP...
    Unless the request has been sent with Connection: close, it's normal that your read blocks, since the connection is purposefully left open to accomodate further exchanges.
    You'll have to parse the data to know when each message is complete. The first empty line (bytes: \r\n\r\n ASCII) denotes the end of the header. The header will have a Content-Length property which tells you how many bytes are left to read.
    Google the HTTP specs if you don't know them.

  • Multiple photo streams on one PC?

    My wife and I each have iPhones and we also have several iPads in the house. We used to use one Apple ID on all the devices.  But with Family Sharing I decided to switch to each person having their own Apple ID but I don't know exactly how this works.
    I want all of our photos to be uploaded to Photo Stream on one PC.  Is this possible?  Will all of our Photo Streams be consolidated into one Photo Stream of the Family Organizer?  Or will they each be in separate streams tied to each Apple ID.  Or should I be using iCloud Photo Library. And will that consolidate the photos?

    Photo stream photos don't use any of your personal storage, but comes with limitations (up to 1000 photos for 30 days and only holds photos...and videos of 5 min or less in shared streams).  If you turn on iCloud photo library that does use your personal iCloud storage, but will host both photos and videos, limited only by the amount of storage in your account.  Also, just so you are aware, turning on iCloud photo library will remove the my photo stream album from your iOS devices, but they can still upload photo stream photos to your computer.
    I know many people are experiencing problems using iCloud photo library right now...guess that's what it's still beta.  You might have to fight it to get it to work.  Be sure to back up your original photos/videos to your computer if your going to use the current beta release.

  • What does the Merge Data Stream processor do when there are multiple input streams to it from the same reader?

    Hi,
    I have a process with a reader of master data that outputs 5 records that feeds simultaneously into 3 different lookup and return processors.
    Each lookup and return processor brings some data back from a detail table. There can be multiple details so I follow each lookup processor with a split records from array processor. Hence I end up with 3 'streams' of data. Stream 1 has 8 records, stream 2 has 5 records and stream 3 has 6 records.
    I join all these streams to a Merge Data Streams processor.
    I end up with 9 records so although the help for the Merge Data Streams processor says 'Merge Data Streams does not perform any transformation, matching, or merging of records' there is clearly some merging going on.
    What is the behaviour of the merge data streams processor in this scenario?
    I have added attributes and flags into each of the streams. How many records should I see and what values should the added attributes/flags have (some records show attributes/flags from all 3 streams whereas others show just those attributes/flags from one stream).
    I have developed a test case simply to understand what the processor is doing but it's not obvious and furthermore it's probably unwise to develop EDQ processes where the processor behaviour is not documented and guaranteed to remain consistent. What I am trying to achieve is to bring all of a person's (the master data) various details (assignments, employers, etc.) together so we can check the data (some rules require data from multiple details).
    Thanks, Nik

    Cheers Mike - and for the explanation of the terms.
    I think I understand now how it's supposed to work.
    What I'm finding however is that when I set a flag to Y at the beginning of a path (that includes a lookup and return and then split records from array processor) that flag is showing no (i.e. an empty) value in SOME of the records shown in the subsequent MDS processor (it's fine the very last split processor before we get to the MDS but then again there are fewer records in that split processor than the MDS).
    In my case there are obviously more records in the MDS processor than there were in the original reader (because the lookup and returns are configured to have unlimited maximum matches). As mentioned, the different paths return different numbers of  records before being combined in the MDS. Say a reader has 5 records and path 1 returns 8 records in total including a path-specific flag (flag1, set to Y) but path 2 (that again adds its own path-specific flag (flag2, set to Y) returns just 5 records (since nothing was added from the lookups) are you saying that flag2 would show as 'Y' for all 8 records shown in the MDS?
    Hopefully you would be able to see what I mean if you try to create a process like the one I've described (or I can upload a package).
    Re. the purpose of the separate paths approach it is simply to allow the visualisation ('showing the working' as Neil puts it) of the different checks being carried out by the process.
    This is considered one of the benefits of the tool over writing SQL queries (with outer joins, query criteria, etc.).
    Also, as mentioned I was following an example that Neil put together for us to ensure that we are doing things in a 'proper' and supported way.
    If we put all the lookups, etc. for all the checks into one datastream then it no longer becomes so understandable and the value of joining processors in a process over simply writing SQL becomes questionable; arguably the EDQ process in fact becomes less easy to understand than simply writing SQL.
    Also, to go down this route I will need to revise the (what was previously substantially working until I revised it) processes that I have already developed.
    Thanks, Nik

  • Multiple ESS's in one Portal connected to different backend systems?

    Hi,
    We have two backend systems installed.
    We have one portal.
    We want to create a second copy of the ESS Portal content connected to the the second backend.
    Datawise this is not a problem.
    But what about the JCo's and the Homepage Framework?
    The WebDympro application seems to look for two specific JCo (for example SAP_R3_HumanResources and ...MetaData) and then both copies of ESS want to use this. Is it not possible to have each copy of ESS use it own JCo's and connect to its own backend system for the Homepage Frameworks?
    Thanks,
    Adriaan

    Adriaan,
    Its NOT possible to even talk to different clients in same backend system because you cannot duplicate the JCos and while creating them you need to specify the system and client details.
    Also it uses a system alias which also has to be unique.
    Per my knowledge one portal instance can talk to only backend client and to talk to another backend / client you will need to create a new instance within the Portal.
    This [help|http://help.sap.com/saphelp_nw2004s/helpdata/en/82/76a2406546ba15e10000000a1550b0/frameset.htm] talks sometihng on multiple backend support. I am not much aware about it but see if it helps you.
    Chintan

  • How to Transform using multiple input sources to one target

    Hello - I'm trying to figure out a way in which I can map retrieved values from more than one table (defined via db adapter links) into a single target flat file (defined via file adapter). I can establish a 1-1 transformation process fine, but when I define a second transformation activity for another table I get an error when I try to run the BPEL process. Does anyone have any ideas on what I can try next? Thanks for helping out the rookie!
    P.S. I'm running SOA Suite 10.1.3.1 with Jdeveloper 10.1.3.1 and connecting to an MS-SQL Server database

    Hi,
    if i understand your question:
    you are getting several variables with values from the db adapters.
    you want to put these variables to the variable, which is the input for the file adapter (this procedure is called the assignment).
    you want to do this assignment with transformations.
    you have to ways to solve that:
    use the assign, which is much less comfortable.
    or
    ask for a feature enhancement via metalink that a transformation support more than one input...

  • Multiple seperate streams to one port?

    DEar all
    Thanks for your help yesterday. I've given up trying to encode data and then tx it over TCP - instead I'm just going to use RTP and encode to a file at the server.
    The next question I have is this:
    The server will receive many connections from many clients. When a client
    a) Can I use one (the same) port on the server for all clients to transmit their RTP to? If so how do I distinguish between the streams on the server? Or must I have separate ports for each incoming stream? If so, how do I find free ports for JMF to use?
    b) How can I identify a particular stream as being from a particular PC (as many maybe behind the same nat). Ideally I'd like to send an identification number first.
    c) How do I detect the end of the stream on the server? Or must the client tell the server via some other means?
    Thanks
    Gareth
    Edited by: 831660 on 28-Jan-2011 02:53

    a) Can I use one (the same) port on the server for all clients to transmit their RTP to? If so how do I distinguish between the streams on the server? Or must I have separate ports for each incoming stream? If so, how do I find free ports for JMF to use?You're supposed to use separate ports for each incoming stream. You should handle this situation using a normal "listen & fork" server routine.
    If you're unfamiliar with the concept, you have a server that listens for incoming requests on a well-known port, and then serves the request on "any available port". Essentially it listens for a request, and then forks off a thread to handle the connection for the client on another port. That way, the well-known port isn't ever "in use"...
    You'll just need to write a basic handshake protocol that your server and client can use. The server listens for requests on some defined port. When it receives a request from a client, it'll pick an unused port, transmit that port back to the client, and then start listening for an RTP connection on the port it told the client.
    b) How can I identify a particular stream as being from a particular PC (as many maybe behind the same nat). Ideally I'd like to send an identification number first.A solves this issue.
    c) How do I detect the end of the stream on the server? Or must the client tell the server via some other means?You're able to listen for the following events on an RTP session by registering a "ReceiveStreamListener" on your RTP session:
    -- NewReceiveStreamEvent, when a new stream arrives
    -- InactiveReceiveStreamEvent, when the stream becomes inactive
    -- ActiveReceiveStreamEvent, when the stream becomes active again after a previous inactive event was generated
    -- TimeoutEvent, when the stream times out.
    -- ByeEvent, when the stream is done.
    So, the end of a stream occurs when you receive a TimeoutEvent or a ByeEvent (which is a subclass of TimeoutEvent so you really only have to handle TimeoutEvents), and you may also possibly want to consider a InactiveReceiveStreamevent to be the end of a stream.

  • File bc: Multiple input files in one folder

    I am working on an integration project, which includes five BPEL processes. These processes are intiated whenever a file is copies in a given folder. The input-filename-pattern for these bpel processes are different (say, input1_%d.txt, input2_%d.txt etc.). But, these files are present in one single folder.
    To implement it, we created one more bpel process, which was bound to file-bc. The first activity in this process is a 'pick' activity. Five operations were defined corresponding to each input-file (name pattern and schema) in the WSDL under single port-type. And, the port-type was bound to the folder where all messages are received. For all five operations, polling interval was defined as 1000 ms.
    For pick activitiy, five 'onMessage' node was created for each operation, which invoked the corresponding (one of five) BPEL process.
    We tested this solution, and it worked. The solution was able to pick five types of input files and invoke the bpel-processes.
    However, the system log of glassfish contains a number of exception error messages. To me, it looks like that all five operations are trying to get the lock on the folder at the same time and this exception is thrown. Though, it does not create any problem in execution of the process, it is a headache for the system administrator.
    Is there any way to control these specific error messages, so that these are not sent to the system log?
    The error message in they system-log is:
    [#|2007-12-21T22:21:40.602-0500|SEVERE|sun-appserver9.1|sun-file-binding.com.sun.jbi.filebc.InboundMessageProcessor|_ThreadID=32;_ThreadName=filebc-ib-Thread-47;_RequestID=15c6d2fe-59e4-4f4f-970f-d13d5d7024ea;|FILBC-IMP0001: inonly message for operation {http://www.servicelive.com/wsdl/HPServiceOrder}AcceptCancelOrder failed processing, an exception was raised. null
    java.lang.IllegalMonitorStateException
         at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:125)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1102)
         at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
         at com.sun.jbi.filebc.InboundMessageProcessor.execute(InboundMessageProcessor.java:343)
         at com.sun.jbi.filebc.InboundMessageProcessor.run(InboundMessageProcessor.java:184)
         at java.lang.Thread.run(Thread.java:595)
    |#]
    [#|2007-12-21T22:21:41.602-0500|SEVERE|sun-appserver9.1|sun-file-binding.com.sun.jbi.filebc.InboundMessageProcessor|_ThreadID=32;_ThreadName=filebc-ib-Thread-47;_RequestID=15c6d2fe-59e4-4f4f-970f-d13d5d7024ea;|FILBC-IMP0001: inonly message for operation {http://www.servicelive.com/wsdl/HPServiceOrder}AcceptCancelOrder failed processing, an exception was raised. null
    java.lang.IllegalMonitorStateException
         at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:125)
         at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1102)
         at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
         at com.sun.jbi.filebc.InboundMessageProcessor.execute(InboundMessageProcessor.java:343)
         at com.sun.jbi.filebc.InboundMessageProcessor.run(InboundMessageProcessor.java:184)
         at java.lang.Thread.run(Thread.java:595)
    |#]
    Thanks,
    Sanjay

    Sanjay,
    Most of the folks that would normally reply are on winter holiday break, so there would be a delay in response. In the mean time, I would really appreciate if you log this as a bug at http://open-jbi-components.dev.java.net. You need to join as an observer to log this bug. You may also want to subscribe to [email protected] and start posting questions there so that you get a fast response from the Open ESB dev team. FYI, Open JBI Components is a sub project of Open ESB and the dev alias at Open ESB is very active.
    Suresh

  • Multiple port opened for one db connection.

    My java standalone server connects to sql server via MS sql JDBC driver(v 2.2). I saw so many port in Time_wait state to the db server in netstat. I did some search on the internet, found that this the nature of TCP/IP protocol. and we can live with it without modifying Windows config.
    however, I noticed on my side, there are two ports involved for each database connection. I think this is one of the reasons I have so many ports in Time_wait state.
    To me, it seems like the request to db server is done on one port, the response from db server is done on another port. is this implemented on JDBC driver layer or on sql server?
    please help !!!

    I saw so many port in Time_wait state to the db server in netstat. This suggests that you are not using any type of connection pooling, but instead are opening and closing connections pretty quickly, although it depends on what you mean by "many"; 10 or 100 might be a good number for a busy system, depending on your application. On some operating systems under high load, it could potentially be a problem if you are getting into many hundreds or thousands, but other issues usually drive people to using connection pools long before this issue would.
    however, I noticed on my side, there are two ports involved for each database
    connection. I think this is one of the reasons I have so many ports in Time_wait state.Not really. That might double the number, but the real reason is a lot of connection closes (real connection closes, not closes on a pooled connection).
    To me, it seems like the request to db server is done on one port,
    the response from db server is done on another port.
    is this implemented on JDBC driver layer or on sql server?That is totally up to the driver vendor; there's nothing you can do about it.
    please help !!!I'm not sure what you're problem really is - you might be worrying about something that isn't a problem. Is something bad happening that you're trying to fix, or did you just notice these expiring ports and start worrying about them?

  • Re: Can we merge two input streams to one stream using JMF?

    Hijo existe un codigo muy util en la pagina de soluciones donde hay un ejemplo de como guardar un archivo desde un datasource... [email protected]

    Hi
    Thanks for your inputs. Can you please send me the code stuff how we can use ObjectRelationalDescriptor. I tried to do that by doing following steps
    1. Crated one class
    oracle.InputOfTypeMap poData =
                        new oracle.InputOfTypeMap();
    poData.setKay("ddd");
    poData.setValue("ddd");
    2. oracle.toplink.objectrelational.ObjectRelationalDescriptor descriptor =
         new oracle.toplink.objectrelational.ObjectRelationalDescriptor();          descriptor.setJavaClass(oracle.iam.reconciliation.vo.InputOfTypeMap.class);      
              descriptor.setStructureName("COL_DATA_PAIR");      
              descriptor.addFieldOrdering("column_name");
              descriptor.addFieldOrdering("data");      
              descriptor.addDirectMapping("key", "column_name");
              descriptor.addDirectMapping("value", "data");
    3. I was not sure how to use this further StoredProcedureCall
    Can you plese help me, how we can do that?

  • Multiple out streams from one Live in stream

    Hi,
    Just wondering is there a viable way to get FMS to stream out
    different bitreates from one live stream?
    /A

    Hi Matthew,
    Welcome to SDN!
    Here is some on-line help. Let me know if you have any other questions.
    http://help.sap.com/saphelp_nw04/helpdata/en/4e/4a75bb7fe211d4b2c50050da4c74dc/frameset.htm
    Cheers! Bill

  • Multiple photo streams to one Macbook

    My wife and I each use different Apple IDs on our iPhones for iCloud and for separate Photo Streams but we only have one family Macbook.  How can both of our Photo Streams link to the one Macbook?

    How can both of our Photo Streams link to the one Macbook?
    Each of you can have their own user account and iPhoto library on the Macbook.  You can use Quick User Switching to move between the two accounts.
    There's no way to have two iCloud accounts link to the same iPhoto Library.  However, with the release of the new Photos application for the Mac early next year and iCloud Drive one account on the Mac may be able to access photos from both iCloud accounts.

Maybe you are looking for