• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

simple socket programming

 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May someone answer?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


What is the usage of this code in program?
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, But MSN messenger, Or Yahoo messenger doesn't manipulate the router.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic