2024年1月25日发(作者:)

72829363738394647484956575859666768697 SendContent(clientSocket, txt); ReceiveControl(clientSocket); } }}

private void Connect(){ try { if (!connected) { passive = false; IPAddress serverIPAddress = (); clientSocket = new Socket(etwork, , ); t(serverIPAddress, 60000); string msg = ReceiveControl(clientSocket); if (("Connected")) { = "Disconnect"; connected = true; } } else { passive = true; SendControl(clientSocket, "Disconnect"); (); = "Connect"; connected = false; } } catch (Exception err) { (("Failed to connect to server, error: {0}", ng())); }}

private void ServerThread(){ IPAddress local = ("0.0.0.0"); Socket server = new Socket(etwork, , ); (new IPEndPoint(local, 60000)); (1); while (true) { Socket receivedClientSocket = (); IPEndPoint clientEndPoint = (IPEndPoint)EndPoint; SendControl(receivedClientSocket, "Connected"); if (passive) { clientSocket = new Socket(etwork, , ); t(s, 60000); string msg = ReceiveControl(clientSocket); if (("Connected")) { connected = true; = "Disconnect"; = ng(); } } while (connected) { string msg = ReceiveControl(receivedClientSocket); switch (msg) {

7576777879868788899697989959759140 { case "Disconnect": (); (); = "Connect"; passive = true; connected = false; break; case "Text": SendControl(receivedClientSocket, "Received"); int length = 32(ReceiveControl(receivedClientSocket)); SendControl(receivedClientSocket, "Received"); string content = ReceiveContent(receivedClientSocket, length); SendControl(receivedClientSocket, "Received"); = content; break; case "File": SendControl(receivedClientSocket, "Received"); string fileName = ReceiveControl(receivedClientSocket); SendControl(receivedClientSocket, "Received"); int fileLen = 32(ReceiveControl(receivedClientSocket)); SendControl(receivedClientSocket, "Received"); ReceiveFile(receivedClientSocket, fileName, fileLen); SendControl(receivedClientSocket, "Received"); ("File Received"); break; } } }}

private string GetFileNameFromPath(string path){ int index = dexOf(''); return ing(index + 1);}

private string RenameConflictFileName(string originalName){ string desktopPath = GetCurrentUserDesktopPath(); int extensionIndex = dexOf("."); string fileName = ing(0, extensionIndex); string extensionName = ing(extensionIndex + 1);

int renameIndex = 1; string newNameSuffix = ("({0})", renameIndex); string finalName = originalName; string filePath = e(desktopPath, finalName); if ((filePath)) { finalName = ("{0} {1}.{2}", fileName, newNameSuffix, extensionName); filePath = e(desktopPath, finalName); } while ((filePath)) { renameIndex += 1; string oldNameSuffix = newNameSuffix; newNameSuffix = ("({0})", renameIndex); finalName = e(oldNameSuffix, newNameSuffix); filePath = e(desktopPath, finalName); }

return finalName;}

private string GetCurrentUserDesktopPath()