• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Connecting 2 different computers while using socket programming in C

 
Greenhorn
Posts: 3
C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the code for my server



And this is code of the client


 
Maneesh Godbole
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23907
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

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic