473,378 Members | 1,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Send data from one pc to another in c#.net

Hiii,
I want to send data from one pc to another. How should i do that??
Can u please send me the code for that as soon as possible?? Because i hav only 8 days to complete my project. i dont have any idea about sending data. the data should be stored on the another pc. Other pc is using SQL server as its database. It can be done in any method lik http request or any other. i think http will not work bcz a m not using asp.net for my application.
May 18 '08 #1
5 22196
kenobewan
4,871 Expert 4TB
Hiii,
I want to send data from one pc to another. How should i do that??
Can u please send me the code for that as soon as possible?? Because i hav only 8 days to complete my project. i dont have any idea about sending data. the data should be stored on the another pc. Other pc is using SQL server as its database. It can be done in any method lik http request or any other. i think http will not work bcz a m not using asp.net for my application.
Please don't simply ask for code. Sounds like you need a tutorial or book. Also check out the FAQs, so you are aware of the site rules. Good luck with your project.

MODERATOR
May 18 '08 #2
Please don't simply ask for code. Sounds like you need a tutorial or book. Also check out the FAQs, so you are aware of the site rules. Good luck with your project.

MODERATOR
Thank you.But it would be great if you could suggest me a few names of the books.Or any tutorial as u mentioned.thank u.
May 21 '08 #3
NitinSawant
270 100+
You can use TCP IP to send data over two computers
May 21 '08 #4
NitinSawant
270 100+
Here's the code:

One computer acts as server and other acts as client,

Expand|Select|Wrap|Line Numbers
  1. //
  2. // Server.cs
  3. // by Nitin Sawant - http://Nitin.uk.to
  4. //
  5. using System;
  6. using System.Windows.Forms;
  7. using System.Net.Sockets;
  8. using System.IO;
  9.  
  10. namespace TCPSocketServer
  11. {
  12.     public class Server : Form
  13.     {
  14.         Button btnStartServer;
  15.         private StreamWriter serverStreamWriter;
  16.         private StreamReader serverStreamReader;
  17.         public Server()
  18.         {
  19.             //create StartServer button set its properties & event handlers 
  20.             this.btnStartServer = new Button();
  21.             this.btnStartServer.Text = "Start Server";
  22.             this.btnStartServer.Click  += 
  23.                 new System.EventHandler(this.btnStartServer_Click);
  24.  
  25.             //add controls to form
  26.             this.Controls.Add(this.btnStartServer);
  27.         }
  28.  
  29.         public static void Main(string[] args)
  30.         {
  31.             //creat n display windows form
  32.             Server tcpSockServer = new Server();
  33.             Application.Run(tcpSockServer); 
  34.         }
  35.         private bool StartServer()
  36.         {
  37.             //create server's tcp listener for incoming connection
  38.             TcpListener tcpServerListener = new TcpListener(4444);
  39.             tcpServerListener.Start();        //start server
  40.             Console.WriteLine("Server Started");
  41.             this.btnStartServer.Enabled = false;
  42.             //block tcplistener to accept incoming connection
  43.             Socket serverSocket = tcpServerListener.AcceptSocket();
  44.  
  45.             try
  46.             {
  47.                 if (serverSocket.Connected)
  48.                 {
  49.                    Console.WriteLine("Client connected");
  50.                    //open network stream on accepted socket
  51.                    NetworkStream serverSockStream = 
  52.                        new NetworkStream(serverSocket);
  53.                    serverStreamWriter = 
  54.                        new StreamWriter(serverSockStream);
  55.                    serverStreamReader = 
  56.                        new StreamReader(serverSockStream);
  57.                 }
  58.             }
  59.             catch(Exception e)
  60.             {
  61.                 Console.WriteLine(e.StackTrace); 
  62.                 return false;
  63.             }
  64.  
  65.             return true;
  66.         }
  67.         private void btnStartServer_Click(object sender,System.EventArgs e)
  68.         {
  69.             //start server
  70.             if (!StartServer())
  71.                 Console.WriteLine("Unable to start server");
  72.  
  73.             //sending n receiving msgs
  74.             while (true)
  75.             {
  76.                 Console.WriteLine("CLIENT: "+serverStreamReader.ReadLine()); 
  77.                 serverStreamWriter.WriteLine("Hi!"); 
  78.                 serverStreamWriter.Flush();
  79.             }
  80.         }
  81.     }
  82. }
  83.  
May 21 '08 #5
NitinSawant
270 100+
Expand|Select|Wrap|Line Numbers
  1. //
  2. // Client.cs
  3. //
  4. using System;
  5. using System.Windows.Forms;
  6. using System.Net.Sockets;
  7. using System.IO;
  8.  
  9. namespace TCPSocketClient
  10. {
  11.     public class Client : Form
  12.     {
  13.         private Button btnConnectToServer;
  14.         private Button btnSendMessage;
  15.         private StreamReader clientStreamReader;
  16.         private StreamWriter clientStreamWriter;
  17.         public Client()
  18.         {
  19.             //create ConnectToServer button, set its properties & event handlers
  20.             this.btnConnectToServer = new Button();
  21.             this.btnConnectToServer.Text = "Connect";
  22.             this.btnConnectToServer.Click +=
  23.                 new System.EventHandler(btnConnectToServer_Click);            
  24.             //create SendMessage button, set its properties & event handlers
  25.             this.btnSendMessage = new Button();
  26.             this.btnSendMessage.Text = "Send Message";
  27.             this.btnSendMessage.Top += 30;
  28.             this.btnSendMessage.Width += 20;
  29.             this.btnSendMessage.Click += 
  30.                 new System.EventHandler(btnSendMessage_Click);                
  31.  
  32.             //add controls to windows form
  33.             this.Controls.Add(this.btnConnectToServer);
  34.             this.Controls.Add(this.btnSendMessage);
  35.         }
  36.         public static void Main(string[] args)
  37.         {
  38.             //create n display windows form
  39.             Client tcpSockClient = new Client();
  40.             Application.Run(tcpSockClient);
  41.         }
  42.         private bool ConnectToServer()
  43.         {
  44.             //connect to server at given port
  45.             try
  46.             {
  47.                 TcpClient tcpClient = new TcpClient("localhost",4444); 
  48.                 Console.WriteLine("Connected to Server");
  49.                 //get a network stream from server
  50.                 NetworkStream clientSockStream = tcpClient.GetStream();
  51.                 clientStreamReader = new StreamReader(clientSockStream);
  52.                 clientStreamWriter = new StreamWriter(clientSockStream);
  53.             }
  54.             catch(Exception e)
  55.             {
  56.                 Console.WriteLine(e.StackTrace);
  57.                 return false;
  58.             }
  59.  
  60.             return true;
  61.         }
  62.         private void btnConnectToServer_Click(object sender,System.EventArgs e)
  63.         {
  64.             //connect to server
  65.             if (!ConnectToServer())
  66.                 Console.WriteLine("Unable to connect to server");
  67.         }
  68.  
  69.         private void btnSendMessage_Click(object sender,System.EventArgs e)
  70.         {
  71.             try
  72.             {
  73.                 //send message to server
  74.                 clientStreamWriter.WriteLine("Hello!");
  75.                 clientStreamWriter.Flush();
  76.                 Console.WriteLine("SERVER: "+clientStreamReader.ReadLine());
  77.             }
  78.             catch(Exception se)
  79.             {
  80.                 Console.WriteLine(se.StackTrace);
  81.             }
  82.         }
  83.     }
  84. }
  85.  
May 21 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SWJust | last post by:
Hi... is it possible to send data from a socket to at physical address (MAC) on f.x another PC or Router ??? I have a IP header with information about another client, and this cannot be altered,...
4
by: ad | last post by:
I want to send a DataSet to WebService, but the DataSet if too huge(there about 50000 records, and 50 fields every record). My solution is 1.save the DataSet as XML file, 2.zip the XML file. 3....
3
by: Simon | last post by:
Hi, I have webpage (sql.aspx) in asp.net with a big textbox. In this box, I generate SQL queries. Some of the queries can takes more than 2000 characters lenght. I want to send the content of the...
1
by: zPaul | last post by:
Maybe, I am asking to wrong group but, here is what I need to do. If you can direct to right direction, I will appreciated it. I will have a web site that the user will interact. Every once in a...
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
1
by: mostafij | last post by:
// This code write random data into a file and every 5 seconds this //program send 5 seconds data into another file. #include <HEADER FILES> FILE *f1,*f2; int main(int argc, char *argv) {...
4
by: Eran.Yasso | last post by:
Hi all, I am trying to write application which runs on my PC that sends data to an application running on Windows mobile. The problem is that the tcp over activesync doesn't work. The device is...
0
by: Xionbox | last post by:
Hello everybody, The error I have seems very easy to solve, but for some odd reason I can't seem to solve it. Anyways, here's my "setup". I created a server running on localhost:1200 (telnet...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.