hi just wanna ask how to transfer a file from a peer-to-peer wired connection a character input from a node to another node.


this is my simple code:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main()
{
  char x;
  
  printf("Enter a character: ");
  scanf("%c", &x);
  getche();
  
}

when the 1st user enter a character, it should be automatically displayed on another node.

have any idea? tnx

Recommended Answers

All 4 Replies

bettybarnes> when the 1st user enter a character, it should be automatically displayed on another node.


Instant messaging, or perhaps IRC

Now seriously, if the example code you posted is a measure of the degree of your knowledge coding in C, you need to focus on building up first some more basic skills, and then a solid foundation, based on practice, practice and more practice.

commented: Nicely put +17

bettybarnes, Aia is right. The simple question you ask has very complicated answers. When your problem space involves multiple, separate computer systems you're going to have to start using some moderately advanced techniques to handle network data.
Do you have any experience with network programming in C? If so, I think more people will be able to help. But if you have never done network programming, I would highly recommend heeding Aia's advice. Repetition is tedious, but it will make it easier in the long-run.

thanks guys. but honestly i dont have any network programming experiences. can i just ping the other node and use net send to transfer a character string to the other node? what do u think guys?

I'm sure someone will correct me if I'm wrong, but I don't think it will be that simple. Network programming is usually a little more complicated than single-terminal programming. You do mean that you want to write a program in C that is capable of sending data to and receiving data from another computer on the network, correct?
If that is the case, you've actually chosen a moderate to advanced task. You see, peer-to-peer programs kind of blur the lines of the traditional client-server model of network communication. To achieve your goal, you'll need to write an application that is both client and server.
For simplicity's sake, lets consider the scenario that you'll just be using a command line interface on two machines (Fred and Barney) that are connected via a simple Ethernet switch. Even at this basic level, Fred and Barney must both have a process that opens a network port to listen for possible connections. Let's say that Fred is the master and Barney the slave. So Fred must open a network port to listen for Barney's connection. Once Barney connects to Fred, Fred will need to establish a connection to Barney - this allows data to flow both directions asynchronously. (There are a lot of different ways that this can be done, but the important part is that Fred and Barney will need to communicate asynchronously). After this portion is done, you can start handling data transfers between the two.
The concept is not very difficult, however; if you're not familiar with C code it will be a very daunting task. The other challenge that you'll have to deal with will be at an operating system level. You'll have to decide if you want to this to be Windows, Linux, Unix or multi-OS, because each major OS has it's own way of communicating with the network layer.
I'm sorry, but the only help that I can recommend is familiarizing yourself with the target operating system's networking and practice writing C code. What helped me jump into writing networked code was writing to and reading from files, it sounds kind of silly but the luxury of Linux is that everything is a file - so the network interface behaves in a familiar way. If you're looking for Windows, I'm afraid I won't be very helpful at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.