• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple socket programming

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try again!

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



this is for client


 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May someone answer?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator











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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to test this program,
Is it possible my computer be client and server?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is the usage of this code in program?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5608
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, But MSN messenger, Or Yahoo messenger doesn't manipulate the router.
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21024
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic