|
Peer-to-peer services require that each peer can see each other peer*, and each peer is capable of receiving data directly from anywhere. In TCP that means every peer must run a server; with UDP it means every peer must be globally visible for incoming connections. If you already have a chat room running on a server, I don't understand why you'd want to get into that.
Peer-to-peer is useful if your server has limited bandwidth and some of the transactions are bandwidth-saturating, if latency is critical or if you have legal concerns about the data being resident (however transiently) on your server. File sharing, the traditional home of P2P, is mostly about the first and a bit about the third. I don't see how any of them apply to a chat service.
* – at least, all the peers that are in the group you want to be able to communicate with.
|
|
|
|
|
You should save the client's socket address as a result of the EndAccept() method. you can then use that socket to communicate with the individual client. If you are dealing with multiple clients then you need to have some sort of login protocol that allows you to map a socket to a particular user. TCP/IP Chat Application Using C#[^] uses this method and should help to explain things for you.
|
|
|
|
|
The way i did was sending the user name to server and a flag with the client with which i want to communicate.
Then server send the message to that particular client on that socket.
So this looks like peer to peer but it is not. It is actually Client -to Server -to - Client.
I guess there should be some way in which we can have Peer ro Peer, may not be using TCP but something else.
|
|
|
|
|
i have textbox that do something on GotFocus.
how i can disable the GotFocus on this textbox ?
and how to enable it back ?
thanks in advance
|
|
|
|
|
Presumably you are talking winforms!
GotFocus is an event, you can't disable it, you can disable the control or you can handle the problem inside the event.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
if you want to disable a textbox, you can use
textbox.enable = false; and true to reanable it ofc.
If you don't like this solution, you can try to overwrite the GotFocus method to only do "something" if you want it.
|
|
|
|
|
Gali1978 wrote: how i can disable the GotFocus on this textbox ?
textBox1.GetFocus -= this.textBox1_GotFocus;
Gali1978 wrote: and how to enable it back ?
textBox1.GetFocus += this.textBox1_GotFocus;
Alternatively, you could set a flag to indicate your "disabledness" and act on that;
bool isFocusEnabled = false;
void this.textBox1_GotFocus(object sender, EventArgs e)
{
if (!isFocusEnabled) then return;
} That'd allow you to disable/enable the execution of the event with a simple boolean.
Bastard Programmer from Hell
|
|
|
|
|
We are producing proofs of files we intend to print; however, the files are sometimes 80 mg in size. Producing a proof with variable data is not an issue. The issue is the amount of time it takes to open and view the pdf's over the web; therefore, the question is...
Is there a way to automatically reduce the resolution of the pdf using C#, VB, C++ or iTextSharp?
Thanks,
Steve
|
|
|
|
|
You'd have to recompose the entire document in order to do that. Any "oversized" pictures would need to be resampled to a lower resolution and put back into the document to reduce it's size. You might just want to compose two documents instead. One with reduced size pictures and another with "normal". If they want the "good" one, you can provide a link to the second download.
|
|
|
|
|
|
Are you accidentally including text as images, instead of text? That is usually why PDFs get huge.
For included images (or other large resources e.g. embedded fonts) within a document, make sure you're using a sensible compression scheme (JPEG or gzip). Complex page streams should also be compressed, but simple ones shouldn't (it makes the file bigger).
|
|
|
|
|
Hi, in my project I tried to backup my database and then restore using SMO. While backing up and restoring it gives no errors and catches no exception. All of them seem to work great. However, after I perform backup to a file, I deleted the data and/or a table from my database to see whether restoring operation will perform correctly or not. However, when I deleted a table or just data in the table, if I perform restore operation, neither the table nor the data in the table comes back. As a result either backup or restore operation does not work correctly. My backup and restore methods are as in the following :
public bool BackUpDB(string DBpath)
{
try
{
ServerConnection srvConn = new ServerConnection(Program.serverName);
srvConn.LoginSecure = true;
srvr = new Server(srvConn);
Backup bkpDatabase = new Backup();
bkpDatabase.Action = BackupActionType.Database;
bkpDatabase.Database = Program.databaseName;
bkpDatabase.Incremental = false;
bkpDatabase.Initialize = true;
bkpDatabase.LogTruncation = BackupTruncateLogType.Truncate;
BackupDeviceItem bkpDevice = new BackupDeviceItem(DBpath , DeviceType.File);
bkpDatabase.Devices.Add(bkpDevice);
bkpDatabase.SqlBackupAsync(srvr);
return true;
}
catch (Exception)
{
return false;
}
}
The following is my restore method :
public bool RestoreDB(string DBpath)
{
try
{
ServerConnection srvConn = new ServerConnection(Program.serverName);
srvConn.LoginSecure = true;
srvr = new Server(srvConn);
Restore rstDatabase = new Restore();
rstDatabase.Action = RestoreActionType.Database;
if (!srvr.Databases.Contains(Program.databaseName))
{
try
{
DbConnection dbcon = new DbConnection("Data Source=" + Program.serverName + ";Initial Catalog=master;Integrated Security=True");
dbcon.ExecuteCommand("CREATE DATABASE "+Program.databaseName, null);
}
catch (Exception)
{
MessageBox.Show("Veritabanı yaratılırken hata oluştu. Program yine de yedeğinizi geri yüklemeye çalışacak. Ancak bu değişiklik programınıza yansımayabilir. Bu durumda bizimle iletişime geçiniz.","Uyarı",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
rstDatabase.Database = Program.databaseName;
rstDatabase.Devices.AddDevice(@DBpath, DeviceType.File);
rstDatabase.ReplaceDatabase = true;
rstDatabase.SqlRestoreAsync(srvr);
return true;
}
catch (Exception)
{
return false;
}
}
I searched on this issue a lot and all of the codes seems correct however I could not understand why it does not perform correctly. Anyone can help me on this issue ? Please it is a bit urgent, Thanks...
|
|
|
|
|
kutbinayi wrote: Please it is a bit urgent, Thanks...
Not even when the code is on fire.
The code looks like it swallows all exceptions. You could try and change the SqlBackupAsync to SqlBackup ; might be throwing something async
--edit;
The same question is in the database-forum; choose a forum and stick with it, cross-posting is annoying.
Bastard Programmer from Hell
|
|
|
|
|
Yes but when I use SqlBackup method then it nevers succeed backup operation. and catches an exception on data object System.Collections.ListDictionaryInternals. I think this object is used by SqlBackup method. If I use SqlBackupAsync then no exception is thrown. I catched all exceptions but it is not seen in the above code. I just use it while I was trying. Is it normal that SqlBackupAsync succeeds the backup operation but restoring the database does not affect the database ? What could be other reasons ?
|
|
|
|
|
kutbinayi wrote: If I use SqlBackupAsync then no exception is thrown.
I bet it is, only on another thread. That would mean that there could have been an exception, without it being reported.
kutbinayi wrote: Is it normal that SqlBackupAsync succeeds the backup operation but restoring the database does not affect the database ?
No, the software usually does as advertised.
kutbinayi wrote: What could be other reasons ?
Some application open (editing the database) while you're doing a restore? That would lock the database and result in an abort.
Can you paste the entire exception that you're getting?
Bastard Programmer from Hell
|
|
|
|
|
The whole exception is this :
Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server 'EMRE-PC\SQLEXPRESS'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Cannot open backup device 'C:\Users\EMRE\Desktop\YEDEK.bak'. Operating system error 5(failed to retrieve text for this error. Reason: 15105).
BACKUP DATABASE is terminating abnormally.
konum: Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
konum: Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
--- İç özel durum yığını izlemesinin sonu ---
konum: Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
konum: Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
konum: Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
konum: Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
konum: Microsoft.SqlServer.Management.Smo.Backup.SqlBackup(Server srv)
--- İç özel durum yığını izlemesinin sonu ---
konum: Microsoft.SqlServer.Management.Smo.Backup.SqlBackup(Server srv)
konum: _15_49KADINIZLEM.DbConnection.BackUpDB(String DBpath) C:\Users\EMRE\documents\visual studio 2010\Projects\15-49KADINIZLEM\15-49KADINIZLEM\DbConnection.cs içinde: satır 107
Backup failed for Server 'EMRE-PC\SQLEXPRESS'.
|
|
|
|
|
Cannot open backup device 'C:\Users\EMRE\Desktop\YEDEK.bak'. Operating system error 5(failed to retrieve text for this error. Reason: 15105).
BACKUP DATABASE is terminating abnormally.
There's your answer. Try a different path.
Bastard Programmer from Hell
|
|
|
|
|
what could be the reason of not accepting this file path ? Because there is no restriction to save file to my Desktop folder.
|
|
|
|
|
kutbinayi wrote: what could be the reason of not accepting this file path ? Because there is no restriction to save file to my Desktop folder.
This is the place where you post whether a different path actually worked or not.
Is there a readonly-file in that location?
Bastard Programmer from Hell
|
|
|
|
|
Ok, but why this does not occur when I use SqlBackupAsync method ?
|
|
|
|
|
kutbinayi wrote: Ok, but why this does not occur when I use SqlBackupAsync method ?
It does. It fails, throwing the exact same exception on another thread. Methods that end with "Async" are executed in a different thread, and you don't get the exceptions that they throw.
Bastard Programmer from Hell
|
|
|
|
|
Ok, thank you for all of your replies. As a result using SqlBackup method instead of SqlBackupAsync is better solution for me. And if i solve the file path problem in my code, then everything seems to work great, right.
|
|
|
|
|
kutbinayi wrote: Ok, thank you for all of your replies.
You're welcome
|
|
|
|
|
Hello,
i have a strange problem with a TextBox.
I use a TextBox to show a ComPort Log. A communication Thread fires a datarecieved event and the Form with the Textbox handles this Event and uses Invoke to change the Content of the (multiline) TextBox.
void ComPortLog_PropertyChangedEvent() {
MethodInvoker ComPortLogChanged = delegate {
textBox2.Text = ComPortLog.Log;
};
if (textBox2.InvokeRequired) Invoke(ComPortLogChanged);
else ComPortLogChanged();
}
After a Timespan (0-30 Minutes) this stops Working? The string in ComPortLog.Log is correct and complete but the string in the Textbox.Text isnt...
somehow this isnt working anymore:
textBox2.Text = ComPortLog.Log;
The string in textBox2.Text is truncated to a value which differs from program run to programrun. Why? The Length of the ComPortLog.Log string is far below MaxLength Property of the textbox.
I tried to use a richTextBox instead, i tried to use the Lines Property instead of Text Property but nothing helps.
The Textbox refuses to show the complete ComPortLog.Log string after a while.
Any suggestions/ideas about this?
|
|
|
|
|
The situation isn't quite clear, and a lot of things could go wrong. Here are some suggestions:
1.
as a test, forget about the GUI, just collect the serial port information and log it to a file, using File.AppendAllText . See if that fails at all.
2.
add try-catch constructs to all related code, and log all exceptions (their ToString value) in a separate file, again File.AppendAllText is the right method.
If you need further assistance, please provide more context, a complete description of your serial source, your serial port's code, and examples of the data when it fails.
|
|
|
|