Question

Java socket code to bypass routers

Asked by: dr_country

Hello, I am kind of new to java programming. I recently wrote a small chat program that works with wired connections from PC to PC. But when I tried it using a wireless connection I believe my router(linksys) would not allow me to do so, even if I was connected to with a wire to the router the same problem. Is there any specific code in Java to eliminate this problem?

Here's what I have to do the connections:

ServerSocket       ssock;
       Socket            client;

//server side
ssock  = new ServerSocket(sock_num);
                  client = ssock.accept();

//client side
client = new Socket(IP,sock_num);

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-05-11 at 17:27:48ID21421285
Tags

java

,

socket

,

connection

Topic

Java Programming Language

Participating Experts
4
Points
150
Comments
30

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. using socks
    i wish to Learning use socks in delphi and make client server application. How can i teach it thanks.
  2. Linksys wired Router to D-Link Wireless Router connectio…
    Hi, I am trying to set up a network between a Linksys wired router and a d-link wireless router. The wired router is hooked up directly to my cable modem and the wireless router is connected to the wired router. The problem is that the wireless router won't see the wired ro...
  3. Socks..Socks...Socks
    Hi all.. I m a newbie to this socks area..which is sucking me for the past 2 hours...finally decided to ask u experts... I am using a LAN connection with http proxy...(IP,DNS provided)...(Streaming,voice,webcam in yahoo,msn blocked..)..Suggested by someone that i can us...
  4. What is better for chat app, Indy socks or delphi's socket…
    Hi there, I've been checking out Indy and I like it, but from a chat app source i've seen it uses a Timer on client, which checks for new text on the server. Is there any other way of sending new text to the clients wihout having them check by themselfs ? Because I really ...
  5. Wireless and wired networks - help!
    We have an existing wired office network with around 20 PCs, some assigned IP addresses dynamically, some static. We have an ADSL router for internet access. I've just bought a wireless laptop and a wireless ADSL router to go with it. While I'm testing the router, we're re...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: objectsPosted on 2005-05-11 at 17:28:56ID: 13983111

What errors are you getting, may be a firewall blocking that port.
If check your firewall configuration and use an open port.

 

by: dr_countryPosted on 2005-05-11 at 17:51:03ID: 13983186

Yes, I've disabled my firewall and also added this port as allowed on both sides. I've even tried placing my router and my own PC in the DMZ.

 

by: aozarovPosted on 2005-05-11 at 18:46:30ID: 13983377

>> I've even tried placing my router and my own PC in the DMZ.
Make sure that your server side is in the DMZ but if both of your comptures are part of the linksys network then there isn't need for
that. Can you provide the stackTrace from your exceptions? Do you run the server before the client (so it will bind and wait before
any clients connection?)

 

by: limaidealPosted on 2005-05-11 at 20:58:18ID: 13983662

Yeah, there's not difference between wired and wireless in socket programming. it must be a configuration issue.

 

by: objectsPosted on 2005-05-11 at 21:48:29ID: 13983785

can you ping the machine your are connecting to?
What about telnetting on the port?

 

by: cincin77Posted on 2005-05-12 at 01:18:26ID: 13984295

Do you mean no messages are sent? Or the large ones for example?

 

by: dr_countryPosted on 2005-05-12 at 12:42:41ID: 13990251

I run the server before the client, but the connection resets when I try to send to the server an object stream. Yes, I can telnet and ping from one PC to another. Another error I get is null, but I haven't tried using the printStackTrace exception which I will try out now. Thanks aozarov. The only thing is I don't really know what you mean by if the server will bind and wait before any clients connection, could you show me a piece of code that does this?

 

by: aozarovPosted on 2005-05-12 at 18:11:49ID: 13992428

see this: http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
You want to make sure that the server created the ServerSocket before the client created its Socket
othewise you will loose that call. If you are using Object streams it is advicable to create first the ObjectOutputStream and then
the ObjectInputStream.

 

by: objectsPosted on 2005-05-12 at 18:15:26ID: 13992438

The server would appear to already being created before the client, otherwise no connection would be made.

> Another error I get is null

Sounds like maybe a NullPointerException somewhere, check the line it occurs on to see if you are referencing a null variable.

 

by: aozarovPosted on 2005-05-12 at 18:22:09ID: 13992459

>otherwise no connection would be made.
I will not be surprised that this is actually the case as well as trying to get from the client Socket (which is null as the constructor
failed) an OuputStream which leads to the NullPointerException.

 

by: objectsPosted on 2005-05-12 at 18:34:45ID: 13992500

It has already been stated that the connection was made.

 

by: aozarovPosted on 2005-05-12 at 18:39:37ID: 13992524

>It has already been stated that the connection was made.
The only thing which come close to that is "but the connection resets when I try to send to the server an object stream" which again leads
me to the same theory.

 

by: objectsPosted on 2005-05-12 at 18:42:21ID: 13992539

For a connection to reset it must first have been made musn't it?

 

by: aozarovPosted on 2005-05-12 at 18:47:09ID: 13992565

>> For a connection to reset it must first have been made musn't it?
Well, I think (and I can see that you don't) that the asker confuse terms and uses "reset" for the case where new Socket(....) failed (or maybe that
he is not aware that this is the point of failure). Adding the stackTrace as I suggested can clear this out pretty easy.

 

by: objectsPosted on 2005-05-12 at 18:52:38ID: 13992596

My apologies for preferring not to make assumptions and going on the facts at hand.
And please refrain from making personal remarks.

 

by: objectsPosted on 2005-05-12 at 18:54:39ID: 13992607

> I run the server before the client, but the connection resets when I try to send to the server an object stream.

Is there any error occurring on the server when this occurs? (Make sure you aren't ignoring any exceptions)
If so, please post the stack trace for that error.

 

by: aozarovPosted on 2005-05-12 at 19:11:38ID: 13992705

>And please refrain from making personal remarks.
Where exactly personal remarks?
I thought it was you that once suggested reading http://www.experts-exchange.com/help.jsp#hi64 but it seems that you keep violating this rule as many others (especially http://www.experts-exchange.com/help.jsp#hi241). This doesn't matter as I am sure you will be happy to hear that I no longer desire to participate in this site (except of answering any open questions I have) as you and CEHJ make my experience in this site very unpleasant. I wish you both all the best with your pursuit for the precious E.E points.

 

by: objectsPosted on 2005-05-12 at 19:26:01ID: 13992783

Where exactly do you feel I have violated the rules? Please accept my apology if I have made your experience unpleasant, it was never my intention. I will say though that sometimes your comments can come across as being a little aggressive, which may have been a misinterpretation and I apologise if so. Thats one of the problems of this form of low bandwidth communication.
Can't speak for CEHJ but I can say he does his best to try and make my life difficult on EE as well :(
As for points, they are worth nothing and in no way drive my participation here, I'm here to help peple solve there problems. Unfortunately there are some who are driven by points at this site (typically ones that are the ones always complaining about points distribution) but theres not much we can do about that.

 

by: objectsPosted on 2005-05-12 at 19:35:56ID: 13992855

aozarov,

This is not really the place for this discussion so feel free to email me directly if you want to discuss this further :)

 

by: dr_countryPosted on 2005-05-13 at 08:51:18ID: 13997007

Hey guys, I really appreciate your interest in trying to help me out with this issue. I still haven't had a chance to print the stack trace in the connection block, but once I have a chance I'm sure I'll come back with a more specific question.

Cheers!

 

by: dr_countryPosted on 2005-05-15 at 18:21:01ID: 14007668

Hello everyone, this time I tried to connect from a public wireless network to a DSL. I had the server side running on the PC with DSL and I ran the client side from the public wireless network. Still no connection...

Here's the output from the printStackTrace:

Error: Connection reset
java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at java.io.ObjectInputStream$PeekInputStream.read(Unkown Source)
        at java.io.ObjectInputStream$PeekInputStream.readFully(Unkown Source)
        at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unkown Source)

        at java.io.ObjectInputStream.readStreamHeader(Unkown Source)
        at java.io.ObjectInputStream.<init>(Unknown Source)
        at SecureChat.<init>(SecureChat.java:257)
        at SecureChat.main(SecureChat.java:394)

Line 257:          ObjectInputStream ois = new ObjectInputStream(client.getInputStream());
Line 394:          is in a catch statement, the last line of code in main

Once again, I am trying to establish a connection, from wireless to wireless, or wired to wireless with/without linksys router. It works for 2 PCs that are connected to their corresponding ISPs directly through their modem. Is there any code in java that can bypass this?

 

by: dr_countryPosted on 2005-05-15 at 18:35:27ID: 14007709

By the way, Objects, if you are still in this thread. Please let me know how you do it to get credit for your solutions. I've solved 2 problems but I did not get any reply and I still have 0 answered questions. Thanks.

 

by: cincin77Posted on 2005-05-15 at 22:44:15ID: 14008231

"Connection Reset" means that you try to connect to a wrong port on the Server. There is no application that listens to the port you try to connect to. Or there may be  a firewall on the server that does not let you connect. The firewall may drop your packets or may send a Reset.

 

by: objectsPosted on 2005-05-16 at 01:20:52ID: 14008666

It looks like you are getting a connection, and the other end is closing the connection.
Are there any exceptions occurring at the other end?

 

by: dr_countryPosted on 2005-05-16 at 20:02:13ID: 14015783

No, the other end just hangs like nothing ever attempted to connect.

 

by: objectsPosted on 2005-05-16 at 20:08:10ID: 14015799

are you sure you are connecting to the right thing :)

 

by: dr_countryPosted on 2005-05-16 at 21:07:33ID: 14015987

Well, it is possible. There is the gateway IP address and then the actual IP address of the host. I try connecting to the host. This is where I think I'm wrong because it is a DSL connection and other computers in the vicinity, that have DSL by the same provider, have the same IP address. I have to somehow connect through the gateway and then have it route to my target IP address.

 

by: objectsPosted on 2005-05-16 at 22:02:40ID: 14016169

Yes it sounds more like a network problem than something to do with your code.
What it sounds like is the connection is being made to something other than your app, and whatever that is disconnects you.

 

by: cincin77Posted on 2005-05-17 at 00:46:55ID: 14016609

hmm..
You should buy a static IP from your Service Provider or you should have a VPN to your server.

regards.

 

by: dr_countryPosted on 2005-05-17 at 09:43:09ID: 14020318

Yes, this was my question in the first place. Since the router sends me back an error message(disconnects/resets) I cannot get to the target host to actually connect to my app. I wanted to know if there was some solid code that could catch this and deal with it appropriately. Oh well, can't have everything. Thanks for your the help guys :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...