• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Connecting 2 different computers while using socket programming in C  RSS feed

 
Greenhorn
Posts: 3
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a simple server client code using sockets in C
They run perfectly fine on same device in different terminals.
How can I make them run using two different computers?
Pl explain in detail as I m a newbie to networking.
Thanks!

Ps: I am using ubuntu on both of my computers.
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have created a simple server client code using sockets in C


Can you show us your code where you connect to your localhost? Connecting to a remote machine should be a matter of just changing the IP address (and port if required)
 
Shivam Saboo
Greenhorn
Posts: 3
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code for my server



And this is code of the client


 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try this out?

I wrote:Connecting to a remote machine should be a matter of just changing the IP address (and port if required)

 
Shivam Saboo
Greenhorn
Posts: 3
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Maneesh Godbole, actually I'm completely new to networking,
Can you tell me what modifications must I make in the code to change ip address and port?
Also after doing necessary changes if both of my PCs are connected to same hotspot will it work or do I have to make some additional changes?
Thanks a lot!
 
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shivam Saboo wrote:
Can you tell me what modifications must I make in the code to change ip address and port?



With the connect() function call on the client, you need to specify the actual address and port of the peer being connected to. With an address of ANY, the only location checked for the peer, would be on the same machine.

Shivam Saboo wrote:
Also after doing necessary changes if both of my PCs are connected to same hotspot will it work or do I have to make some additional changes?



Whether it works or not depends on the network setup. And as long as you have the correct address, any additional changes is likely to be network changes, and not changes to your program.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!