473,408 Members | 1,826 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,408 software developers and data experts.

How would I sand a file through a stream using this socket:

#using <mscorlib.dll>
#using <System.dll>

#include "stdlib.h"
#include "stdio.h"

using namespace System;
using namespace System::Text;
using namespace System::IO;
using namespace System::Net;
using namespace System::Net::Sockets;

void Connect(String* server, Int32 port, String* message)
{
try {
// Create a TcpClient.
// Note, for this client to work you need to have a TcpServer
// connected to the same address as specified by the server, port
// combination.
//Int32 port = 13000;
TcpClient* client = new TcpClient(server, port);

// Translate the passed message into ASCII and store it as a Byte
array.
Byte data[] = Text::Encoding::ASCII->GetBytes(message);

// Get a client stream for reading and writing.
// Stream stream = client->GetStream();

NetworkStream* stream = client->GetStream();

// Send the message to the connected TcpServer.
stream->Write(data, 0, data->Length);

Console::WriteLine(S"Sent: {0}", message);

// Receive the TcpServer::response.

// Buffer to store the response bytes. data = new Byte[256];

// String to store the response ASCII representation.
String* responseData = String::Empty;

// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream->Read(data, 0, data->Length);
responseData = Text::Encoding::ASCII->GetString(data, 0, bytes);
Console::WriteLine(S"Received (Response Data): {0}", responseData);

// Close everything.
client->Close();
} catch (ArgumentNullException* e) {
Console::WriteLine(S"ArgumentNullException: {0}", e);
} catch (SocketException* e) {
Console::WriteLine(S"SocketException: {0}", e);
}
Console::WriteLine(S"\nSocket closed!");
Console::WriteLine(S"\n Press Enter to EXIT.");
Console::Read();
}

int main()
{
system("TITLE Client Conection System.");
String* NameServer;
Console::WriteLine(S"Name of Server to conect to: ");
String __gc * input = Console::ReadLine();
NameServer = input->ToString(0);
redo:
Int32 InPort;
Console::WriteLine(S"\nPort (Usal port is 1300): ");
String __gc * input1 = Console::ReadLine();
InPort = input1->ToInt32(0);

if(InPort=0)
{
Console::WriteLine(S"\nERROR: Incorect port number!");
goto redo;
}

String* InMessage;
Console::WriteLine(S"\nMessage to send: ");
String __gc * input2 = Console::ReadLine();
InMessage = input2->ToString(0);

Connect(NameServer, InPort, InMessage);
return 0;
}

/* You have to include -clr in the compiler option to compile this.
THX!

*/

--
Message posted via http://www.dotnetmonster.com
Nov 17 '05 #1
0 1088

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
0
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the...
7
by: simonrigby_uk | last post by:
Hi all, Sorry if this is the incorrect group but I couldn't see anything directly relevant. Can someone confirm for me what happens when two network streams are sent to an application at the...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
2
by: White Spirit | last post by:
I have a function within an application where a client connected to a server continuously sends data. The code on the server side is of the following form: Socket socket = receiveSocket;...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
3
by: Bonzol | last post by:
Hello Everyone, I have been looking around a lot to create a server app which can accept multiple client connections and receive files. So far I have combined a few examples and added lots of my...
2
by: cmrhema | last post by:
Hi All , I have with me a server socket program, I am receiving all the clients, but what happens is i have to write it into a file. This consumes time. So we do not have a data loss, but as...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.