This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes simple socket programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "simple socket programming" Watch "simple socket programming" New topic
Author

simple socket programming

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

Can you be elaborate on who is the Client and Server? From Your earlier post, I assume - Your Friend's computer is the client and your computer as the Server.

abalfazl hossein wrote:The story is, I ran this program on his computer, for first time, His computer be as server and client,as time that I ran on my computer, On my computer it works, But on his computer it throws that exception.


Please be specific on these facts- Are both Client and Server running on same machine- Your or your friends? or both running on different machines? In which case- who is the server and client. To connect to a computer you need to know a way to communicate with it- Knowing its Public IP address and the port on which the application is running.


Mohamed Sanaulla | My Blog
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
both Client and Server are running on same machine.

because I decide to show him my program, Then first I decide to show him how it works,But it does not work....

and my friend make

and me
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18499
    
  40


A "connection reset" means that the network plumbing went down; and it is a notice from the system. It could be caused by anything. The network can be configured to timeout the connection (on either side). The other side could have closed the connection. Or there could even be some sort of firewall running, that prevents the connection (even on the same machine).

IOW, the only way to debug it, is to probably load up a network sniffer to hunt it down.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Ok,I went to his home this night, and it doesn't work again!


I use netbeans5.5 in his home.

I don't think I come again to his home.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18499
    
  40

abalfazl hossein wrote:My IP address [?]: 94.183.229.216 [Whois] [Reverse IP]
My IP country code: IR
My IP address country: ip address flag Iran, Islamic Republic of
....



Ahhh... Okay. Why are you telling us this?

Henry
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
I try again!

My other fired lives in another city, I sent for him server code:



this is for client


abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
May someone answer?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41045
    
  43
It looks like both client and server exhibit the Don't println to a Socket bug. (There may be other problems, but that one jumped out at me.)


Ping & DNS - my free Android networking tools app
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635











run:
Server: HELO
Server: Hi there
Server:
Server: .
ok
Ok


When I type Ok, Nothing happened

and also it does not print ouit
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41045
    
  43
Ulf Dittmer wrote:It looks like both client and server exhibit the Don't println to a Socket bug. (There may be other problems, but that one jumped out at me.)
Mihai Calin
Greenhorn

Joined: Jan 10, 2011
Posts: 2
i want to test this program,
Is it possible my computer be client and server?


Jocuri online | Jocuri barbie
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Yes, But you must use your IP, I also wanted to check through the internet, If you like please send PM for me,
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635


What is the usage of this code in program?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

That code snippet - reads the Line from the stream and then prints it on the standard output. If the line contains "Ok" it breaks out of the loop.

Anyways, I see that this thread is marked as Solved.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635






I change the code and it does not print anything.

reads the Line from the stream and then prints it on the standard output. If the line contains "Ok" it breaks out of the loop.



But I don't see any sentence in that code that contains "OK".You can check original site:
http://www.javaworld.com/jw-12-1996/jw-12-sockets.html?page=3
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41045
    
  43
Why are you ignoring my posts? As long as your socket code calls "readLine" or "println" it's liable not to work correctly (or not at all).
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635

Sometimes this program does't work and folks told me it is about firewall or maybe my computer is behind a NAT

Then how other programs access to internet without any problem?If it is a permission, I can give permission and it isn't necessery to turn off firewall.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18499
    
  40

abalfazl hossein wrote:
Sometimes this program does't work and folks told me it is about firewall or maybe my computer is behind a NAT

Then how other programs access to internet without any problem?If it is a permission, I can give permission and it isn't necessery to turn off firewall.


Well, if you are behind a NAT server, you should have no problems accessing the internet. A NAT hides you from the internet, it doesn't hide the internet from you.

If you want a machine on the internet to get you a NAT'ed machine, you will need to configure the server to forward ports to your machine.

Henry
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Thanks Sir,

If you want a machine on the internet to get you a NAT'ed machine, you will need to configure the server to forward ports to your machine.


May you explain more?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3573
    
  14

Well, your clients need to use some sort of IP address and port to make contact with your server. If your server is in a LAN, it has a local IP address which is not visible to your clients. What you need to do is configure your router (which has an IP address that *is* visible to your clients) to forward any packets it receives on a specific port to your server.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Thanks, But MSN messenger, Or Yahoo messenger doesn't manipulate the router.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8834
    
    7

I posted about port forwarding in this thread three weeks ago (see my post of Thursday, December 30, 2010 08:05:57). It looks like you're chasing your tail at this point.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

abalfazl hossein wrote:Thanks, But MSN messenger, Or Yahoo messenger doesn't manipulate the router.

That's because they're clients, not servers. They initiate the connection instead of listening for incoming connections.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18499
    
  40

abalfazl hossein wrote:Thanks, But MSN messenger, Or Yahoo messenger doesn't manipulate the router.


Actually it does, but something tells me that it would be a good idea to understand what was discussed already first.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple socket programming
 
Similar Threads
JAVA SOCKET PROGRAMMING
problem with java.net.SocketException at client site
sending mail using servlet
TCP Threaded Server Client Question
bugs in client\server program - can't connect to remote server