Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: How should i do tracing in c# using zipkin Pin
Pete O'Hanlon11-May-17 21:08
mvePete O'Hanlon11-May-17 21:08 
AnswerRe: How should i do tracing in c# using zipkin Pin
Gerry Schmitz12-May-17 8:42
mveGerry Schmitz12-May-17 8:42 
QuestionHow to Transfer xml file from remote server to another Pin
Member 1265997911-May-17 0:16
Member 1265997911-May-17 0:16 
QuestionRe: How to Transfer xml file from remote server to another Pin
Richard MacCutchan11-May-17 0:39
mveRichard MacCutchan11-May-17 0:39 
AnswerRe: How to Transfer xml file from remote server to another Pin
John C Rayan11-May-17 5:50
professionalJohn C Rayan11-May-17 5:50 
GeneralRe: How to Transfer xml file from remote server to another Pin
Member 1265997911-May-17 17:28
Member 1265997911-May-17 17:28 
GeneralRe: How to Transfer xml file from remote server to another Pin
dlhale11-May-17 19:05
dlhale11-May-17 19:05 
GeneralRe: How to Transfer xml file from remote server to another Pin
Member 1265997911-May-17 19:40
Member 1265997911-May-17 19:40 
private void FileSave()
{
SqlConnection con = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand("Sp_Rep", con);
cmd.CommandType = CommandType.Text;
con.Open();
string val = cmd.ExecuteScalar().ToString();
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(val);
xmldoc.Save("C://Shankar//Shankar.xml");
FromLocal();
ToRemote();
con.Close();
}
public void FromLocal()
{


try
{
//string hostName = Dns.GetHostName(); // Retrive the Name of HOST

// Get the IP
//string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();
Console.WriteLine("That program can transfer small file. I've test up to 850kb file");
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
// m_socWorker = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
//String szIPSelected = "172.31.1.111";
//String szPort = "80";

String szIPSelected = "10.2.2.28";
String szPort = "580";
int alPort = System.Convert.ToInt16(szPort, 10);


System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint ipEnd = new System.Net.IPEndPoint(remoteIPAddress, alPort);
sock.Connect(ipEnd);


//IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any);
// Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
///Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
// sock.Bind(ipEnd);
sock.Listen(100000);
//clientSock is the socket object of client, so we can use it now to transfer data to client
if(ipEnd != null)
{
Socket clientSock = sock.Accept();
string fileName = "Shankar.xml";
string filePath = "C://Shankar//Shankar.xml";//Your File Path;
byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);
byte[] fileData = System.IO.File.ReadAllBytes(filePath + fileName);
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);
fileNameLen.CopyTo(clientData, 0);
fileNameByte.CopyTo(clientData, 4);
fileData.CopyTo(clientData, 4 + fileNameByte.Length);
clientSock.Send(clientData);
Console.WriteLine("File:{0} has been sent.", fileName);
clientSock.Close();
Console.ReadLine();
}
}


catch (Exception ex)
{
Console.WriteLine("File Receiving fail." + ex.Message);
}

}
public void ToRemote()
{
try
{
Console.WriteLine("That program can transfer small file. I've test up to 850kb file");
IPAddress[] ipAddress = Dns.GetHostAddresses("localhost");
IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 5656);
Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
clientSock.Connect(ipEnd);
byte[] clientData = new byte[1024 * 5000];
string receivedPath = "C://Shankar//Shankar.xml";
int receivedBytesLen = clientSock.Receive(clientData);
int fileNameLen = BitConverter.ToInt32(clientData, 0);
string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen);
Console.WriteLine("Client:{0} connected & File {1} started received.", clientSock.RemoteEndPoint, fileName);
BinaryWriter bWrite = new BinaryWriter(System.IO.File.Open(receivedPath + fileName, FileMode.Append)); ;
bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen);
Console.WriteLine("File: {0} received & saved at path: {1}", fileName, receivedPath);
bWrite.Close();
clientSock.Close();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("File Sending fail." + ex.Message);
}
}
GeneralRe: How to Transfer xml file from remote server to another Pin
Richard MacCutchan11-May-17 21:09
mveRichard MacCutchan11-May-17 21:09 
Questionnotification text click event Pin
Member 1319194310-May-17 6:02
Member 1319194310-May-17 6:02 
AnswerRe: notification text click event Pin
NotPolitcallyCorrect10-May-17 6:10
NotPolitcallyCorrect10-May-17 6:10 
AnswerRe: notification text click event Pin
Gerry Schmitz10-May-17 6:57
mveGerry Schmitz10-May-17 6:57 
AnswerRe: notification text click event Pin
OriginalGriff10-May-17 8:03
mveOriginalGriff10-May-17 8:03 
QuestionRe: notification text click event Pin
CHill6010-May-17 23:26
mveCHill6010-May-17 23:26 
AnswerRe: notification text click event Pin
John C Rayan11-May-17 5:52
professionalJohn C Rayan11-May-17 5:52 
QuestionC# windows application system and cloud Pin
Zeyad Jalil9-May-17 23:41
professionalZeyad Jalil9-May-17 23:41 
AnswerRe: C# windows application system and cloud Pin
Dave Kreskowiak10-May-17 2:35
mveDave Kreskowiak10-May-17 2:35 
AnswerRe: C# windows application system and cloud Pin
Afzaal Ahmad Zeeshan10-May-17 5:31
professionalAfzaal Ahmad Zeeshan10-May-17 5:31 
QuestionC# Network and streams Pin
TheTrigger9-May-17 11:12
TheTrigger9-May-17 11:12 
AnswerRe: C# Network and streams Pin
Bernhard Hiller9-May-17 21:30
Bernhard Hiller9-May-17 21:30 
GeneralRe: C# Network and streams Pin
TheTrigger10-May-17 2:26
TheTrigger10-May-17 2:26 
GeneralRe: C# Network and streams Pin
Dave Kreskowiak10-May-17 2:38
mveDave Kreskowiak10-May-17 2:38 
GeneralRe: C# Network and streams Pin
TheTrigger10-May-17 2:52
TheTrigger10-May-17 2:52 
GeneralRe: C# Network and streams Pin
Dave Kreskowiak10-May-17 4:31
mveDave Kreskowiak10-May-17 4:31 
GeneralRe: C# Network and streams Pin
TheTrigger10-May-17 5:48
TheTrigger10-May-17 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.