|
Can you provide us with more details? What have you tried so far ?
Post your code here.
When you say different network , how do you connect to the network? Do you have permission to connect to the network? ( Credentials etc).
|
|
|
|
|
Yes thats the problem how to connect remote system using ip address using coding
|
|
|
|
|
Show us some code
Tell us where the code breaks
What works
What dosen't
We're not claivoiant
|
|
|
|
|
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);
}
}
|
|
|
|
|
|
can you send me the c# code as how to add a click event for the notification text that appears in the notification window to "[DELETED]@gmail.com"
[edit]Email removed - OriginalGriff[/edit]
modified 10-May-17 14:03pm.
|
|
|
|
|
We don't write code to order here.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
Yeah .. sorry about that.
This is actually the "no free" Code Project.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Nope. And do yourself a favour: Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Did you mean to post this in a forum at the bottom of an article? You are more likely to get an answer to your question if you post in the appropriate place. We have no idea what notification window you are referring to
|
|
|
|
|
Which C# code are you referring to ? Don't assume that we are taking orders here.
|
|
|
|
|
Hi,
I have a product (Financial System) connected to SQL server databases via Web Service,
I need to make this product as a cloud service such as I will publish the web service on My servers and also publish the clients SQL databases on our servers and the clients only download the client application (Financial System) and install it on their PC's.
Please let me know what is the best case to manage the clients accounts and registrations and what is the best solution for this.
Thanks All
|
|
|
|
|
Nobody is going to be able to answer this question as we know absolutely nothing about your system and requirements. There are lots of ways to do this, but what you do is up to you and your research against your requirements.
|
|
|
|
|
Zeyad Jalil wrote: I need to make this product as a cloud service such as I will publish the web service on My servers and also publish the clients SQL databases on our servers and the clients only download the client application (Financial System) and install it on their PC's. Do you know what you want, or want to build?
A cloud service, has nothing to do with that much of hosting, downloading. A cloud service is a cloud service, you just publish once. There is not this much of a churn in the process and you provide not the application, but models; Saas, PaaS etc.
What you should focus on is SaaS. You would require to build it that way, then purchase any cloud subscription to get started and learn how they would support your needs.
Going cloud is of no use, if there is a lot of Ops going on everywhere.
Quote: Please let me know what is the best case to manage the clients accounts and registrations and what is the best solution for this.
Same, you have to think of these things first. On cloud, you are also provided an amount of data. But, what to purchase? 1) Relational database 2) No SQL database? That depends entirely on your data, your needs and your customers.
Share some more insights, so that we may guide you on this concept.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Hello guys, i really need help for this
i'm writing in C# a client-server (not important maybe, but it's for a game), probably i need more knowledge and clarification about the process.
Firts of all, the process is the same for client and server, and EVERYTHING IS (+or-)WORKING.
My code should explain what i'm doing
new Thread(() =>
{
int i = 0;
while (true)
{
byte[] bytes = new byte[102400];
NetworkStream stream = client.GetStream();
int received = stream.Read(bytes, 0, bytes.Length);
Console.WriteLine("Packets: " + ++i);
var basepacket = TNetwork.Encaps.Deserialize(bytes, 0, received);
Thread.Sleep(1000);
}
}).Start();
But there are some points that i don't get.
1) If i Send packets quickly
while(spamtest)
bp.Send(stream, ...);
the other point doesn't process all incoming data if it is busy (send 1000, processed 200). How to solve? i won't lose informations. there are no a kinda of SampleAndHold system? How is possible that i'm losing tcp packets just cause the program was busy??
2) I tried to send some data of 2k over the network (with another pc) but i had no problems. MTU is 1500 so my endpoint should crash getting incomplete binary-serialized-classes ! No?
I'm going crazy. My implementation is ok or i'm missing something?
3) Maybe client.GetStream(); can i only write or read at once? If i write, can't read? neither with 2 threads?
4) Probably i have to separate the Send process to a Queue in another thread.
5) What does exactly the flush()? I need to use it? I tried with and without Flush() after stream.write no differences (autoflush is false).
6) if i let client spam 70.000 packets, at the end one of both crashes
Help me please, getting crazy. Thanks
modified 10-May-17 8:17am.
|
|
|
|
|
Your code shows some misunderstandings: the inner while loop will start many threads in very short intervals - likely long before any of the already started threads has finished its work. A short wait time in between may be appropriate.
Your comment
// Do works ... Consider that classes are shared between clients and servers
// so classes are Invoked ... is unintellegible. What is the problem you want to solve with that? And why do you think your solution does so?
Also, I don't see any use of int i = 0 .
The code may become better readable when you refactor the bodies of the threads into functions.
Also note that an exception in a thread may crash your program if you don't handle it inside that thread.
|
|
|
|
|
Hi, i have removed useless code.
Now you can see, with Thread.Sleep(1000) i lose a lot of packets (more time, more loss. ~1000sent, ~40received). The above sketch code is the receiver.
What can I do to avoid losing packets?
Yes i know about handle inside threads
Hope you can help me, Thanks
|
|
|
|
|
You put the thread that is receiving data to sleep for 1 second upon the receipt of data and you wonder why you're losing packets?
|
|
|
|
|
Yes, i lose packets anyway.. Without .Sleep i get 1000sent/800received.
Client and server are in the same pc actually
|
|
|
|
|
You should never have a Sleep anywhere in your network code.
Also, you're receive code seems to think that when a client sends a message, you get the entire message in one go without regard to a message potentially being split up into multiple Reads. You Read however many bytes are told you received and deserialize them, even if the message is incomplete. The next read will also fail to deserialize properly because now you don't have the first part of the message but you have the trailing end of it, not a complete message.
Your losing "messages", not packets. Those are two totally separate concepts and cannot be used interchangeably.
It would seems that your client and server code has no method of delineating messages from each other. Where in the stream of bytes read can your code determine that a new message has started? You should only try to deserialize the data when you are sure you have a complete message in the buffer. That's what you have to implement.
|
|
|
|
|
> You should never have a Sleep anywhere in your network code
Using Sleep only for the example to emulate a computational delay
You are right, i'm confusing packets and messages sorry and thank.
I missed to say that: if i send messages slowly, the receiver can handle all messages without any issues.
The problem is when i send more message than the receiver can handle. Maybe i'm mad, but i won't lose messages!
The strange thing is, if i send a 2KB message over the network, the message have to be splitted, right? Cause of MTU. i should receive 2 messages? I still receive one, no crashes. So i need clarity.
As i said in the main post, i get crash only if i send a lot of messages much quickly
modified 10-May-17 11:57am.
|
|
|
|
|
If a message exceed the data payload size of a packet on a pipe, it is broken into multiple packets. You cannot attempt to deserialize the data until all packets for the message have been received. You're current code doesn't do that.
Your server code has no method of telling a client that 1) data is coming and this is how many bytes to expect (header), the data itself, and a checksum to validate that the data is OK (if necessary). These things do not have to be separate messages.
The client should not attempt to deserialize the data unless it 1) saw the message header and knows how many bytes to expect, 2) captured the data in the buffer, and checksummed the data to make sure it was OK (if necessary).
If the client receives anything it doesn't recognize or too few/many bytes, it should not attempt to deserialize the data. It should (optionally) tell the server to resend the data and go back to waiting for a new header.
|
|
|
|
|
So you suggest to send 4 bytes that's the length of the message and a some bytes for the checksum, which protocol you suggest for the cksum? md5? there are something lighter?
I will do that (after fix message loss)
Any ideas to avoid loss of messages?
thanks for your time guys
|
|
|
|
|
Normally, I would start with a message delineation marker, say 3 bytes of 'F0', then a 32-bit message length, then then message. The checksum is options, but if it's used, that would be supplied after the message length and before the message. Typically, the message is going to be a variable length so it should show up last.
|Start of Message|Length in bytes|CheckSum|Message bytes...|
| F0 F0 F0 | 00 00 00 1A | F6 |data bytes... |
You don't get it. This may just fix your message loss because as your code stands right now, since you don't have any way of knowing when a message begins and ends, you have no way of knowing if the data you deserialize is valid! You could be deserializing the end bytes from the last message combined with the beginning bytes of the next message thinking it's valid when it's not.
|
|
|
|
|
Problem solved .. you were right when you said "you're receive code seems to think that when a client sends a message, you get the entire message in one"
Now everything works perfectly
public static void CopyStream(Stream input, Stream output, int MaxLength)
{
int read, totalread = 0;
byte[] buffer = new byte[81920];
while (totalread < MaxLength)
{
read = input.Read(buffer, 0,
(
((MaxLength - totalread) < buffer.Length) ?
(MaxLength - totalread) :
buffer.Length
)
);
if (read == 0) break;
totalread += read;
output.Write(buffer, 0, read);
}
}
modified 12-May-17 10:05am.
|
|
|
|
|