Multithread program with socket, help me

Hi all, I have had some troubles with my multithread program, that is when I make 4 threads to send messages to 4 accepted ports: 2001, 2002, 2003 and 2004, it leads to the error:
"Java.net.SocketException: Software caused connection abort: recv fail"
I cannot understand why this exception is inconsistent. Please help me figure out
solution for this problem. Thank you.
Here is my code
public synchronized void sendREQMessage(Message obj)
     for(int i=2001;i<=2004;i++)
          try
                         obj.setPortDest(i);
                         myThread thread=new myThread(obj,i);
               catch (Exception e)
                    System.out.println(e);
public myThread(Message obj,int i)
          message=obj;
          port=i;
          start();
     public void run()
          try
               message.setPortDest(port);
               connection = new Socket("127.0.0.1",port);
               out = new ObjectOutputStream(
     connection.getOutputStream());               
               out.writeObject(message);
               out.flush();
               //connection.close();
          catch(Exception e)
               System.out.println(e);
     }

I'm sorry, I cannot understand what you mean.
Sometimes, the message can be sent well among 4 ports. Sometimes, it leads to the error:
"Java.net.SocketException: Software caused connection abort: recv fail"
And I don't know why.
Thank for your help

Similar Messages

  • Re: is it possible to program with Sockets with the Internet as a network.

    I am working with socket programming.
    During the Christams holidays I will need to do some programming at home.
    Is it possible to program with sockets on a home PC using Windows with only the Internet as a network?

    yes it is
    I am also working on an application that uses sockets at the moment, and I asked help a lot by these days ;)
    Maybe I can help you from what I've learned..
    here is a basic:
    create server socket:
    ServerSocket server = new ServerSocket(4444);
    4444 is the port on which the socket is listening
    Socket socket = new Socket("127.0.0.1",4444);
    127.0.0.1 is a local IP adress to connect to and 4444 is the port number to connect to. That considers that the server and the connecting client are both on the same PC, but then you can use other IPs ;)
    Hope it helps

  • Remote doesn't program with TV, help using cable box volume

    Hello, I have just had Fios installed in my home and my remote is not able to program with my TV. I have a Magnavox TV and it is old, The installer said that my TV is unable to be programmed with my remote which is why I am here. I have tried every opion in the Control manual to no success. The remote I have is a VZ P265v2 RC and the code for my TV brand is 222 (which doesn't work). I can live without the power opion and the others that come with it, but I need the volume to work since I do not have a remote for my televsion. So my question is, is there a way I can have my remote just use the cable box itself as a volume control without it being programed to the TV if you understand what i mean.
    I apologize for the horrible sentences grammar and any confustion, I don't exactly know how to exsplain what I want. I know the Cable box has its own volume setting and the TV has its own volume setting, I want to be able to just use the cables to adjust the volume with the remote.
    ~Edit~
    I have found the opion I want to use in the Audio settings called "Set-Top Box Volume", now is there a way I can bing this opion to my remote volume keys so I dont have to go into the settings each time to adjust the volume

    It is set to variable in the audio option, and I assume its using Coax or component cables to connect the STB to the TV since the installer did it himself, and I honestly don't know what those are. I have a wire from my wall connected to my box and then the box is connected to the TV.
    I also have multiple other boxes in my home that was just installed as well, and were able to be programmed for the TV using the remote, and the volume controls the actual TVs volume, not the STB volume which is in the opions. Thats the volume control in which I want to use//the only one I seem to be able to use via the control but its only accessable threw the opion and its quiet inconvient since differnt channels seem louder and quieter then each other.
    So same question stands, is there a way to use the volume buttons on my Controler to use the STB Volume not the actual TV's. It is current set on variable, not fixed and still no go. And once again I have tried the command codes to program the remote and doesnt work, even tried using them all via pressing the <OK> and the FIOS TV buttons then holding the PLAY button for quiet a few minutes and still a no go.

  • How to run Struts program with the help of tomcat

    Hello Everybody
    This is Adesh.I am a newcomer of java and facing a problem with struts, so if any one know how to set the path of struts and how to run struts program, so plz inform me.
    THX in Advance.............................................

    struts-config.xml
    <struts-config>
    <action-mappings>
         <action path  = "/welcome"
                    type  = "Welcome"
                    scope="session">
                <forward name="success" path=".welcome"/>
                <forward name="failure" path=".base.error"/>
         </action>
    </action-mappings>
        <plug-in className="org.apache.struts.tiles.TilesPlugin">
            <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>
            <set-property property="definitions-debug" value="1"/>
            <set-property property="definitions-parser-details" value="0"/>
            <set-property property="definitions-parser-validate" value="true"/>
        </plug-in>
    </struts-config>tiles-defs.xml
    <tiles-definitions>
         <definition name = ".base" path = "/include/template.jsp">
              <put name = "title" value = "${title}"/>
              <put name = "header" value = "/include/top.jsp"/>
              <put name = "body" value = "${body}"/>
              <put name = "footer" value = "/include/footer.jsp"/>
         </definition>
    </tiles-definitions>web.xml
    <servlet>
            <servlet-name>action</servlet-name>
            <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
            <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/struts-config.xml</param-value>
            </init-param>
    <init-param>
                <param-name>definitions-config</param-name>
                <param-value>/WEB-INF/tiles-defs.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
    <servlet>
            <servlet-name>init</servlet-name>
            <servlet-class>Init</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
      <jsp-config>
        <taglib>
            <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/wall.tld</taglib-uri>
            <taglib-location>/WEB-INF/wall.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/c.tld</taglib-uri>
            <taglib-location>/WEB-INF/c.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/fn.tld</taglib-uri>
            <taglib-location>/WEB-INF/fn.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/fmt.tld</taglib-uri>
            <taglib-location>/WEB-INF/fmt.tld</taglib-location>
        </taglib>
    </jsp-config>
        <resource-ref>
            <description>DB Connection</description>
            <res-ref-name>jdbc/SQLServerDB</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
    </web-app>This should help....

  • Client-Server programming with Sockets

    How to read user input from GUI in client socket and send the data to server socket? Can someone give example of the coding?
    Thank you.

    Take a look at reply 28 of Program hanging on a Thread. That post is a swing based socket client. If you are using Swing you must ensure that all swing activity occurs on the AWT Event Dispatch Thread. That's the reason for the use of invokeLater.
    Reply 21 on the same thread is a multithreaded command line server.

  • Make a litlle program with sockets.

    Hi All,
    I'm a newbie in java network applications and now I have a litlle problem.
    I start my SrvScan program, so I start my ScanSystem program.
    When ScanSystem connects at SrvScan, I have the following error:
    Exception in thread "main" java.lang.NullPointerException
    at SrvScan.main(SrvScan.java:23)
    See my code for SrvScan:
    1 import java.net.ServerSocket;
    2 import java.net.Socket;
    3 import java.io.*;
    4
    5 public class SrvScan {
    6 public static void main( String args[] )
    7 {
    8 Socket cs = null;
    9 ServerSocket ss = null;
    10 String msg = null;
    11
    12 try {
    13 ss = new ServerSocket(3000);
    14 cs = ss.accept();
    15
    16 BufferedReader in = new BufferedReader( new InputStreamReader( cs.getInputStream() ) );
    17 BufferedWriter out = new BufferedWriter( new FileWriter("dados.txt") );
    18
    19 while ( in.readLine() != null )
    20 {
    21 msg = in.readLine();
    22 out.flush();
    23 out.write(msg, 0, msg.length());
    24 out.newLine();
    25 }
    26
    27 out.close();
    28 in.close();
    29 cs.close();
    30 ss.close();
    31 } catch ( IOException e ) {
    32 System.out.println( e.getMessage() );
    33 }
    34 }
    35 }
    Thanks,
    Rodrigo Nascimento

    Hi,
    The following error:
    Exception in thread "main" java.lang.NullPointerException
    at SrvScan.main(SrvScan.java:23)Informs you that you get a NullPointerException at line 23 in the file SrvScan.java.
    Nullpointer exception means that you are dereferencing something which is null. Line 23 is:
    out.write(msg, 0, msg.length());So, now we know that either out, or msg is null (since that are the only objects which are dereferenced on that line. Line 22 is:
    out.flush();
    And that line does not throw NullPointerException. So we know that out isn't null. That means that msg is null. Correct that problem.
    Kaj

  • Unable to send .mp3 with sockets, help!

    I need to send my .mp3 files throw a server but it stays in stuck in out.write(lenght), any suggestions for another type of way to do this...
    Other files are sent fine, .pdf, .txt, .doc... i might be the size but how to solve it...
    try {
                Socket socket=null;                 
                socket = new Socket(GlobalValues.ipOut, GlobalValues.portOut);
                OutputStream out = socket.getOutputStream();     
                InputStream fis = new FileInputStream(f);
                int length=0;
                BufferedInputStream buf = new BufferedInputStream(fis);
                //byte[] buffer = new byte[9*9*1024];
                GlobalValues.creatTextArea("                 Uploading PLEASE WAIT...", 1, Color.red, 0); 
                while((length = buf.read()) != -1){
                    out.write(length);
                    out.flush();
                GlobalValues.creatTextArea("                  FINISHED upload", 1, Color.green, 0);             
                fis.close();
                out.close();
            catch(Exception e){
                e.printStackTrace();
            }

    OutputStream out = socket.getOutputStream();     OutputStream out = new BufferedOutputStream(socket.getOutputStream());
    int length=0;This is not a correct name for this variable. You are reading bytes from the input stream, not lengths. A better name would be 'data'.
    while((length = buf.read()) != -1){
    out.write(length);
    out.flush();Move this flush to after the loop.
    If you're blocking in the write() it means the reader is slow reading. Using the BufferedOutputStream may fix this.

  • Need help with sockets!

    I am fairly new to network programming. All help is very appreciated!
    I know how to work with sockets and serversockets, and how to transmit data between the host and the clients. My problem is that I have no idea how to get my working program to work online.
    -It works fine when I have both the client and host programs running on my computer.
    -It works fine when I have the host on one computer (192.168.1.103), and the client running on another one (192.168.1.102 I think). I guess in this case I'm just using the linksys network, not the internet.
    -IT DOES NOT WORK WHEN I upload the files to my website, and run them from there. I am not sure what the cause is; the host correctly creates the serversocket and waits, but never receives a connection to the client. The client seems to connect; it does not throw any exceptions, and creates a socket, but never actually communicates with the host.
    Could the problem be with my applets' permissions?
    What hostname/IP should I have the client connect to? It is on the same server, so would localhost work, or do I need to connect to my websites ip, or to the hostname?
    What other problems could there be?!?!?!?!
    Thank you so much for your help!!!!!!!!!!

    Donv7 wrote:
    1) Is the server program running on the same machine as the webserver?
    2) How are you opening this Socket in the applet? You mentioned something about localhost, that would be wrong. You should use the www hostname. Same as the host that served the HTML that the applet lives in.1- My server program and client program are actually the same thing. This doesn't sound too good.
    And applet is not a suitable endpoint for a P2P application. An applet is going to be a client. Not a server.
    Are you actually running a server (of your program) on the webserver? Or are you hoping that two applets will talk to each other with one acting as a server? Because that's not going to work.

  • Help with Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    This was all working yesterday, but this morning, I cannot run in the dev fabric, or even setting the website project as a startup project directly, I get the following error:
    Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.BadImageFormatException: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    Assembly Load Trace: The following information can be helpful to determine why the assembly 'msshrtmi' could not be loaded.
    === Pre-bind state information ===
    LOG: User = Andrew-VAIO\Andrew
    LOG: DisplayName = msshrtmi
    (Partial)
    WRN: Partial binding information was supplied for an assembly:
    WRN: Assembly Name: msshrtmi | Domain ID: 3
    WRN: A partial bind occurs when only part of the assembly display name is provided.
    WRN: This might result in the binder loading an incorrect assembly.
    WRN: It is recommended to provide a fully specified textual identity for the assembly,
    WRN: that consists of the simple name, version, culture, and public key token.
    WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
    LOG: Appbase = file:///C:/Users/Andrew/Desktop/Beko2011Azure/Website/
    LOG: Initial PrivatePath = C:\Users\Andrew\Desktop\Beko2011Azure\Website\bin
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\Users\Andrew\Desktop\Beko2011Azure\Website\web.config
    LOG: Using host configuration file:
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
    LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/cb955b02/eef106e2/msshrtmi.DLL.
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/cb955b02/eef106e2/msshrtmi/msshrtmi.DLL.
    LOG: Attempting download of new URL file:///C:/Users/Andrew/Desktop/Beko2011Azure/Website/bin/msshrtmi.DLL.
    ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
    Stack Trace:
    [BadImageFormatException: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
    System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
    System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
    System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
    System.Reflection.Assembly.Load(String assemblyString) +28
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
    [ConfigurationErrorsException: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
    System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
    System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
    System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
    System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
    System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677
    [HttpException (0x80004005): Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9079228
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
    System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +258
    Note that the dev machine is x64 Win7.
    I have not tried deploying this to staging since the issue started as I'm a bit nervous of touching the staging/live environment until this is solved.
    Removing the PlatformTarget element from the project file has no effect
    Removing the msshrtmi.dll file from the bin directory of the website project ends up with 
    'Could not load file or assembly 'Microsoft.WindowsFabric.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified'
    I have used Git to revert to the last working build to no effect (But I don't have the obj/bin folders in GIT), but it has atleast reset the project files etc.
    If I return msshrtmi.dll to the bin folder and switch the model and website projects to x64 there is no change
    If I switch both to x86 then I get an error Could not load file or assembly 'BekoModel2011' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    which is the model project - presumably because to run on my x64 machine I need the 64bit version?
    I really need to be able to debug and then publish some changes ASAP.
    Andrew

    Hi,
    Is it true that you're using IIS to host the application? Could you check whether the process is x64 or x86 one via task manager or config in IIS manager?
    http://blogs.msdn.com/b/rakkimk/archive/2007/11/03/iis7-running-32-bit-and-64-bit-asp-net-versions-at-the-same-time-on-different-worker-processes.aspx
    Allen Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • TS3989 Mssage when opening Photo Stream on-"This file does not have a program associated with it for performing this action. Please install a program or, if one is already installed, create an association in the Default Programs control panel" Help!!!

    Mssage when opening Photo Stream on-"This file does not have a program associated with it for performing this action. Please install a program or, if one is already installed, create an association in the Default Programs control panel" Help!!!

    You are posting in the "icloud on my mac" forum, but your profile mentions Windows.  If using a mac, you need to have iphoto or aperture installed in order to receive new photos via photo stream.  If using windows, try posting in the iCloud on a PC forum.  You'll get better help there.
    https://discussions.apple.com/community/icloud/icloud_on_my_pc

  • When I turn on my PC with Vista 64 bits it gives a message "ApplephotoStreams.exe has stopped working. Windows will close program.  Please help.

    When I turn on my PC with Vista 64 bits it gives me a message "ApplePhotoSream.exe" has stopped working correctly. Windows will close the program.
    Please help!!!

    Hi, I have the same problem. Has anyone come forward with any advice on fixing the problem?

  • Help! Can't open Labview program with MATLAB codes !!!

    They used to work! But today I just can't open any LabView program with MATLAB codes in. This also happened some time ago, but after a day I tried again, it went back to normal. Can anyone help me fix it? Many thanks !!!

    Hello BLpig,
    Thank you for your inquiry regarding problems opening a VI. It sounds like a VI containing MATLAB code will not open in LabVIEW. This problem can happen when using LabVIEW 7 on a Windows 2000 machine. Assuming this is your setup, the following link is a great resource when dealing with this issue.
    http://digital.ni.com/public.nsf/websearch/4475BC3CEB062C9586256D750058F14B?OpenDocument
    Other resources similar to this can be found on the ni.com website by clicking the support tab at the top of the home page. Then search for �open vi matlab� from Technical Resources at the top of the page or topics similar to this. I hope these resources help. Let me know if I can further assist you.
    Shea C.
    Applications Engineering

  • Photoshop keeps crashing...saying an attempt was made to load a program with incorrect format.  Can anyone help?

    photoshop keeps crashing...saying an attempt was made to load a program with incorrect format.  Can anyone help?

    You can
    Supply pertinent information for quicker answers
    The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:
    Adobe product and version number
    Operating system and version number
    The full text of any error message(s)
    What you were doing when the problem occurred
    Screenshots of the problem
    Computer hardware, such as CPU; GPU; amount of RAM; etc.

  • I want parameters with f4 help for program names in value request

    I want parameters with f4 help for program names in value request
    points will be awarded if  useful

    lv_name1 TYPE name1,        "Vendor Name
    CALL FUNCTION 'POPUP_TO_SEARCH_VALUE'
        EXPORTING
          textline1   = 'Vendor Name'(f09)
          titel       = 'Enter'(f17)
          valuelength = 35
        IMPORTING
          value       = lv_name1.
    try this out ..

  • I can't activate my programs even though I paid for a subscription.  I did a chat with the help desk and they didn't solve my problem.  I want to cancel my account.  Please contact me since the chat is down

    I can't activate my programs even though I paid for a subscription.  I did a chat with the help desk and they didn't solve my problem.  I want to cancel my account.  Please contact me since the chat is down

    Activating after a Find My iPhone lock bricks the device if you don't know the password used by Find My iPhone.
    Read through this article to find if your device has an activation lock.
    http://www.macworld.com/article/2048739/get-to-know-ios-7-activation-lock.html
    If this is what you have - the news is bad:
    http://www.cultofmac.com/246755/why-ios-7s-activation-lock-is-a-disaster-waiting -to-happen/

Maybe you are looking for

  • ALV list with only 1 field

    Hi guru's, I want to create an ALV list with only a char255 field. <all_table> contains data of sflight and is of type sflight(dynamically). I want to show the data as one line. CALL FUNCTION 'DDIF_FIELDINFO_GET'        EXPORTING             tabname 

  • Error while invoke ADF BC Service component

    I have an ADF Service component, which I'm trying to call from BPEL. A process can be sucessfuly build and deployed, but at run time I'm getting error: Could not determine WSDL port. A error stack trace from server is below: 2008-12-04 21:02:33.003 W

  • Problem with CmdLineLauncher - Connection unavailable

    I have problem with CmdLineLauncher. When i execute this tool by task scheduler during night, i get error message: Launch Vars: {ExecDB=Planning...} 2011-12-18 03:31:22,674 WARN main com.hyperion.hbr.cmdlnlauncher.CmdLineLauncher - Connection unavail

  • Procedure file at OS level

    Hi All, I gone through the wrap utility to encrypt the stored procedures. I created a procedure called test_proc in scott schema. But in wrap utility they mentioned to provide the procedure file as input to encrypt. if i create procedure it will be s

  • Facebook on a MacBook has hundreds of glitches

    I've just recently created a new profile on Facebook and can't get it to work properly, which is driving me crazy! Basically, nothing stays the same on it when I change or update the information: profile picture (thumbnail different to the main pic,